Hi all,
I found a trigger on a previous post which successfully prevents the record from saving when a field other than the name is not unique (code below). I have implemented this in Memento desktop and synced it with the cloud. it works.
The next step is to combine 2 or more fields so the combination is unique. This is to ensure no duplicated entries. Similar to a composite primary key in SQL.
the outcome of the trigger would be to prevent a save if the combination already exists in the library.
Is there anyone out there who has completed this and can share the Javascript or have any ideas on how to implement it?
This is different from setting more than one field as Name, as Name is given to another field in the library which is a Link to Entry in another library.
Setting more than one field as Name in a library is fine, BUT when using Link to entry from another library it concatenates all of the Names into the Link to entry field. This is not what I am after.
Thanks in advance.
Tim
code for unique entry
var myField = entry().field("myField"); // Value of myField
var entries = lib().entries(); // Array containing all the entries in the library
var unique = true; // Presuming, initially
for (var ent = 0; ent < entries.length; ent++) { // Loop through all entries
if (entries[ent].field("myField") === myField) // If there is ever a match,
unique = false; // Remember it
}
if (!unique) { // If not unique,
message("myField is not unique. Try again."); // Tell the user
cancel(); // Disallow the save
}