lastModifiedTime - undefined?

200 views
Skip to first unread message

Allsorts

unread,
Apr 7, 2017, 8:09:19 PM4/7/17
to mementodatabase
Hi,

I can't get the new javscript entry() property lastModifiedTime to work. The best I can get is "undefined". I've tried with an existing library and new library in an existing group and complete new group and library. I fully expect the reason for it not working is my bad code but:

As it's a property of entry()  I'd expect "lastModifiedTime" or "entry.lastModifiedTime" or entry().lastModifiedTime in a Javascript field would work but no all show as "undefined".

Tried a trigger script: Updating and Entry > Before Saving the Entry (and After Saving Entry):

var e = entry;
e().set("moddtg",e.lastModifiedTime);

Runs succesfully but the text field "moddtg" is set to "undefined". Using a Time, Date or Date/Time field as the target doesn't work either. Altering the e.lastModifiedTime bit to some quoted text or another field works. I can't get "creationTime" or "author" to work either.  B-(

Bill Crews

unread,
Apr 7, 2017, 9:16:11 PM4/7/17
to mementodatabase
entry() is a global function, so you don't prefix it with anything. It just returns the Entry object associated with the Event. e() would be a totally different function.

To reference any of en Entry object's properties, just use <Entry object>.<property name>, like entry().name.

So, I opened an existing library of mine that already had an Update/Before trigger, and added one line.

The line was:

message("Last modified " + entry().lastModifiedTime);

After I edited and modified the first entry, I pressed the checkmark icon and saw the following at the bottom of the screen for two seconds:

Last modified Fri Apr 07 21:11:15 EDT 2017

Is this what you wanted? It is a JavaScript Date Object, so you can look up all the things you can do with a Date object and do it to entry().lastModifiedTime. If those things don't light your fire, you can check the box that says to load the moment.js library, and if you do that, you can then do all the things moment() can do with a Date object, which you can see at momentjs.com.

Allsorts

unread,
Apr 9, 2017, 7:58:29 AM4/9/17
to mementodatabase
Hi Bill,

Thanks for the quick reply. Think it's best to say what my goal is. I want some means of seeing, without having to do anything (other than perhaps scrolling) when an arbitary record was last updated or created. I was hoping that entry().lastModifiedTime and entry().creationTime would do this but they aren't working as I'd expect.

Being playing a bit more. No trigger scripts and two JS fields with the following JS:

moment(entry().creationTime).format('[Created: ] Do MMM YYYY HH:mm');
and:
moment(entry().lastModifiedTime).format('[Updated: ] Do MMM YYYY HH:mm');

These work producing the wanted formatted output, however the times shown are the same. Both show the last time "edit the library" was saved. So two "features":

1) The creationTime is not that as shown under "Record view > 3 dots > Info > Created".

2) Saving an "edit the library" is altering individual records "Modified" time (3 dots > Info > Modified) but the information in those records hasn't been altered, only the database structure. Note an individual records "3 dots > Info > Created" time is not altered.

If you edit and save a record both dates, entry().creationTime and entry().lastModifiedTime, change to the time of that record save. Again the "3 dots > Info > Created" time is not altered.

I don't think I have any typos here on on my device but curiously if you alter say "entry().creationTime" to "entry().tionTime" you don't get an error...

Cheers
Dave.

Bill Crews

unread,
Apr 9, 2017, 11:14:50 AM4/9/17
to mementodatabase
Expressions for JavaScript fields are a little different from other scripts, like triggers. The current library and entry are assumed, so entry() and lib() aren't needed and don't make sense. I tried referencing creationTime and .creationTime, and neither works.

In general, tripping you use the scripts (Memento JavaScript Library) API from a JavaScript field won't work, though I haven't tried everything myself.

It sounds like you would need to do what you're doing in a Creating / Before opening and an Updating / Before opening trigger script, especially the latter. It should work there. You'd see it in an Entry View card, but not updated yet in a list entry.

Allsorts

unread,
Apr 9, 2017, 6:06:25 PM4/9/17
to mementodatabase
On Sunday, 9 April 2017 16:14:50 UTC+1, Bill Crews wrote:
> Expressions for JavaScript fields are a little different from other scripts, like triggers. The current library and entry are
> assumed, so entry() and lib() aren't needed and don't make sense. I tried referencing creationTime and .creationTime, and
> neither works.

Agreed "creationTime" or "lastModifiedTime" give a "ReferenceError: "lastModifiedTime" is not defined".
".creationTime" or ".lastModifiedTime" give a syntax error.
"entry.creationTime" or "entry.lastModifiedTime" work as previously described for entry().

Is there a bug tracker to report such things?

> It sounds like you would need to do what you're doing in a Creating / Before opening and an Updating / Before opening trigger
> script, especially the latter. It should work there. You'd see it in an Entry View card, but not updated yet in a list entry.

I'll have a play, I'm not that worried about the creation time but the modification time has to reflect the time an entry is saved and preferably only when something is changed and saved. <later> This works but doesn't honour the changed and saved part:

Library field:
Type: Date/Time
Name: Updated
Default: Current Date
Display in List: As status.

Trigger Script:
Name: Update Time
Event: Updating an entry
Phase:After saving the entry
Script: entry().set("Updated", new Date());

Note "After saving the entry" may mean the change of update time doesn't show in the record view you are returned to even though it has taken place. "Before Saving entry" doesn't have this feature.

Cheers
Dave.

Reply all
Reply to author
Forward
0 new messages