JavaScript Help

108 views
Skip to first unread message

Chris Kelley

unread,
Jan 17, 2018, 11:40:51 AM1/17/18
to mementodatabase
Hey folks,

I am using MD for hobby management and JavaScript is not one of my hobbies. I was wondering if someone could assist me. I'm trying to find something that will either completely move an entry from one library to another after a checkbox has been ticked. At the very least copy the info and then I could filter the original list to not show checked off items.

I have tried using this reference: http://wiki.mementodatabase.com/index.php/Trigger_Examples
Specifically "Copying the value of a Checkboxes or Multiple-choice field to another library" but again I don't really understand JavaScript.

Thanks for reading.

Bill Crews

unread,
Jan 19, 2018, 10:20:46 AM1/19/18
to Chris Kelley, mementodatabase
To do this, first make a copy of the structure of your library. From the libraries list, locate your library, press the 3-dot menu in the icon's upper-right corner, select Copy, and select Structure only. This library will later contain entries from your original library that have been copied to the new one. Let's call these libraries Original and Copy. Let's call the checkbox field Move?.

Then, in Original, create a library action (wiki page Actions) and possibly a trigger (wiki page Triggers).

The action (and possibly the trigger) may be called Move checked.  The script should be as follows...

var copylib = llibByName("Copy"); // Requires authorization (shield icon, top bar of script editor)
var entries = lib().entries();
for (var ent in entries) {
   var entry = entries[ent];
   if (entry.field("Move?" == true) {
      copylib.create( {
         FieldName: entry.field("FieldName"),
         FieldName2: entry.field("FieldName2"),
         ... // The rest of your fields
         } );
      entry.set("Move?", false);
      }
   }

...With this, you can press the Play button in the top bar of the entries list at any time to move all checked entries to the Copy library.

If you'd like this to run automatically entry time you open Original, you can put the same script into an Opening the library trigger. Then you won't have to keep running the action explicitly.

If you want to differentiate between entries that been moved and those that have never been moved in Original, introduce a new checkbox field Moved and add the following line to the script right after the entry.set() statement...

      entry.set("Moved", true);

...This way, you can always highlight these entries in Original and delete them, if you like.

Chris Kelley

unread,
Jan 19, 2018, 3:02:45 PM1/19/18
to Bill Crews, mementodatabase

This is great, thank you so much! I will attempt to put this into place later.

Reply all
Reply to author
Forward
0 new messages