script for entry duplication

86 views
Skip to first unread message

Stoval

unread,
Feb 7, 2018, 8:49:33 AM2/7/18
to mementodatabase
Hello,

I am trying to create action that would duplicate whole previous entry except for date/time fields, which should be updated with current date and time. Currently, as the workaround, I am doing it manually - long press last entry, copy and than edit content. Not the most elegant solution. I thought it would be a straightforward code, but than I found this thread:

https://groups.google.com/forum/#!searchin/mementodatabase/duplicate$20entry|sort:date/mementodatabase/xCH_Erbvvoo/P7Dx2-wjAwAJ

I attempted to follow this solution:


var entries = lib().entries();

lib().create({

field1:entries[0].field("field1"),

field2:entries[0].field("field2"),

field3:entries[0].field("field3"),

field4:entries[0].field("field4")

});


This seems to be working through fields 1-3, until field4, which is link to many field - that field remains empty. What am I doing wrong? Isn't there a simpler solution to copy whole entry into new one within same library on entry creation?

Bill Crews

unread,
Feb 7, 2018, 3:44:17 PM2/7/18
to Stoval, mementodatabase
Certain field types don't work in the standard way, so you have to deal with then differently. Dates are one, and links are another.

If it is a one-to-many link, then just put a [0] after the field() method. If it is a many-to-many link, you'll have to loop through all the links and link each one.

With dates, by default, you get a string to display (groan), so you have to do a gettime() method or something like that to get what you want. Then to format for display, you can use formatting methods of either the Date object or of the moment.min.js JavaScript library.
Reply all
Reply to author
Forward
0 new messages