Copy a field to an existing field in another library

62 views
Skip to first unread message

Harry Contos

unread,
Sep 8, 2025, 1:15:52 AM (4 days ago) Sep 8
to mementodatabase
My goal is to copy a field‘s value to an identical field in a different Library.
I have looked at the Wiki and several searches in Google but I can’t get it to work.
Any examples or actual code would be great.
Two libraries:
Lib1
Lib2
Fields:
Myid
Can
Notes
I have a field “myid” in both libraries with identical data. Should be used as a link between the two liberties to identify the records.
The Notes field is the data I want added to the second Library Lib2 from the “Notes” field in Lib1.
Thanks

Bill Crews

unread,
Sep 8, 2025, 11:28:56 AM (3 days ago) Sep 8
to Harry Contos, mementodatabase
Why? Are you linking libraries? How?

To copy a field to another library, one would create 2 scripts, one in a Create After Saving event and the other a duplicate of that script under Updating After Save in Lib. Something like this...

If you're linking from Lib to Lib2...

entry().field("link")[0].field("Notes")

...or if not, then something more like...

let Lib2 = libByName("Lib2");
if (Lib2 == null) {
    message("Lib2 not found");
    cancel();
    exit();
}
Lib2.set("Notes", entry().field("Notes"));


--
You received this message because you are subscribed to the Google Groups "mementodatabase" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mementodataba...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/mementodatabase/e8a93f1a-9693-407e-8b41-0786c3315e41n%40googlegroups.com.
Message has been deleted

David Gilmore

unread,
Sep 9, 2025, 6:20:19 AM (3 days ago) Sep 9
to mementodatabase
I suspect the OP really wants to copy the contents of the field.

Here is how I would do it:

Before Create Trigger code:

SaveRecord(entry());

Before Update Trigger code:

SaveRecord(entry());

Shared Script code:

function SaveRecord(e) {
  // Fetch the list of pointers to the remote entries through the local link field (even if there is only one)
  var entries = e.field("LinkFieldName");
  if (entries.length > 0) {  // ensure there is a link
    var r = entries[0];  // Get the first pointer
    r.set("RemoteFieldName", e.field("LocalFieldName")); // Sets the contents in the remote entry
  }
}

This assumes that there is only one linked remote record. If you do not have that embedded link, then you would have to do a "libByName("namne").find" type operation.

Bill Crews

unread,
Sep 9, 2025, 10:13:33 AM (2 days ago) Sep 9
to David Gilmore, mementodatabase
I think mine does copy the contents of the Notes field in Lib2 to the save field in Lib2.

Anyway, regardless, at least the Create trigger and probably both it and the Update trigger need to be After Save. 


David Gilmore

unread,
Sep 9, 2025, 11:33:09 AM (2 days ago) Sep 9
to mementodatabase
Your right in that the "after" create trigger would be better (but it will work in the "before" create trigger if the user is the one that creates the link. But after is better.). Does not matter for the update trigger.
Reply all
Reply to author
Forward
0 new messages