I would like a script to duplicate an entry from entries list updating date and Unique ID # fields

425 views
Skip to first unread message

KAB

unread,
Jun 10, 2021, 1:56:53 AM6/10/21
to mementodatabase
My library has  a variety of fields, but only two that need to change in the duplicate.
An entry# field set as unique in the Main tab "Unique Fields" and set to autoincrement by default.
It also has a date field set to current date by default.

Issue 1) I would like the duplicated entry to use the current rather than the source entry's date for my date field.

Issue 2) I would also like the entry number field to get the next entry number field. This seems tricky as I don't see how to access the global? variable that tracks the next number from the autoincrement function.

I imagine this will be an "entry view card" script.

I'm assuming issue 1 can be addressed with an field assignment to current date, but solving issue 2 is a mystery to me. I do have a script that finds the last used Entry # from the last created entry, but I imagine there is a function/variable that already has this value.

I'm new to Memento DB so will appreciate some help and direction please.
Thanks  much for any help!

Er Mo

unread,
Jun 10, 2021, 3:45:35 PM6/10/21
to mementodatabase
Hallo
Wie läuft der vorgang des Kopierens ab . Verwendest du dafür ein Skript . Würde eine Neuen Eintrag erstellen lassen . Da wird das Aktuelle Datum eingetragen . Müsst mit der ID Nummer auch so gehen .

Hello
How does the copying process work? Do you use a script for this. Would create a new entry. The current date is entered there. Must also go with the ID number.

KAB

unread,
Jun 10, 2021, 8:22:28 PM6/10/21
to mementodatabase
I have not yet written the script.
I am hoping someone more experienced with Memento than I am will provide some suggestions of how best to proceed.
My key questions are the items 1 & 2 I identified in OP.

I also wonder if there is something like an EntryObject() for current entry that I can copy to Defaultentry() as a template for the duplicate that already will have all fields already setup and with the values of the source entry filled in. Then I just need to fix the date and Entry # field values.
Thanks!

Er Mo

unread,
Jun 11, 2021, 1:59:12 AM6/11/21
to mementodatabase
Hallo
In Memento wird das so gemacht .Du öffnest den Gewünschten Eintrag. In den Einträgen ist die Schaltfläche für das Aktionsskript . Das Skript beziecht sich auf den Eintrag der ausgewählt ist . Von da werden die Datengenommen und ein Neuer eintrag in dieser Bibliothek erstellt .

Hello
This is done in Memento. You open the desired entry. In the entries is the button for the action script. The script refers to the entry that is selected. The data is taken from there and a new entry is made in this library.

Er Mo

unread,
Jun 11, 2021, 2:07:09 AM6/11/21
to mementodatabase
Skript:
var uab =lib()
var neu1 = new Object();
    neu1[F1] = e.field(F1);
    neu1[F2] = Variable;
   uab.create(neu1);

Er Mo

unread,
Jun 11, 2021, 2:11:26 AM6/11/21
to mementodatabase
Hallo
Das Skript gehört unter Aktionen / Einstigaktion gespeichert .Das " F1 " und " F2 " ist der Feldname . bei F2 kann eine Variable übergeben werden .

Hello
The script should be saved under Actions / Entry Action. The "F1" and "F2" are the field names. a variable can be transferred with F2.

Er Mo

unread,
Jun 11, 2021, 2:14:14 AM6/11/21
to mementodatabase
Vergessen :
Das Feld mit den aktuelle Datum muss nicht erstellt werden , wird automatisch gemacht . Versuche das mit den 2 Werd auch den du ändern willst

To forget :
The field with the current date does not have to be created, it is done automatically. Try that with the 2 Will you also want to change

KAB

unread,
Jun 11, 2021, 5:01:41 AM6/11/21
to mementodatabase
Ernst,
Thanks for the help!
Your e. object wasn't defined so please see what I did.

This fails to transfer all the items in the entry I am trying to duplicate. The duplicate command in the three dot menu does transfer everything.

This code does create a new entry with a Unique ID which I get from the last entry in the entries list +1.

How do I reference a field in the entry I am duplicating? E.g., What is its index number x in e[x].field("a field name")?

My current code. It's not pretty.

var thislib = lib();
var e = lib().entries();
var nuentry = new Object();
var x;

x = e[0].field("Entry #") + 1;
nuentry["Entry #"] = x;
nuentry["Activity"] = "script test"; //e.field("Activity");
nuentry["Name"] = e[5].field("Name")[0].field("Common Name");  // test to get a name from linked library's first Field
thislib.create(nuentry); // make the new entry
message("Duplicate created. Entry # " + x);

Thanks much!

Er Mo

unread,
Jun 11, 2021, 2:57:27 PM6/11/21
to mementodatabase
Hallo
Die Zahl in [ ] Klammer ist der Datensatz in der Bibliothek . Memento zählt rückwerts . Der [0] Eintrag ist der Letzte erstellte Datensatz .

Hello
The number in [] brackets is the record in the library. Memento counts backwards. The [0] entry is the last data record created.

KAB

unread,
Jun 12, 2021, 7:37:58 PM6/12/21
to mementodatabase
Hi,
This is my current script trying to emulate the menu > duplicate command and then update a few fields in the duplicate.
However, it only has the fields I explicitly name in script's assignments or that have a default value in the new entry. So it is not a duplicate because 10 other fields were not copied.

Important question: Is there a mechanism in Memento Javascript to do what the Duplicate command does?

I imagine something like, but have no idea obviously:
thislib.createduplicate(nuentry); // magic command to make nuentry an identical DUPLICATE of current entry.

Thanks very much!

// My script
var thislib = lib();
var el = lib().entries();
var e = entry();

var nuentry = new Object();
var x, thisenum;
var linkedEntry = e.field("Name")[0];

x = el[0].field("Entry #") + 1;    // make new entry #

nuentry["Entry #"] = x;
nuentry["Activity"] = e.field("Activity").join(); // Convert activities array to string
nuentry["Name"] = linkedEntry;

thislib.create(nuentry); // make the new entry

thisenum = e.field("Entry #");
message("Duplicate of " + thisenum + " created. Entry # " + x);
Reply all
Reply to author
Forward
0 new messages