3
votes

I want your help to get Server Date and Time when action is performed. e.g. Submit, Approve, Reject etc

var myDoc:NotesDocument = data_source.getDocument().

I have tried following but failed to get server time this always stores client date and time specially when its executed on client.

myDoc.replaceItemValue("ApprovedOn", session.createDateTime(@Now());

following generates error / exceptions.

myDoc.replaceItemValue("ApprovedOn", @Now());

OR

var curr_Date = @Now();
myDoc.replaceItemValue("ApprovedOn", curr_Date);

OR

var mDt:NotesDateTime = session.createDateTime(@Now());
myDoc.replaceItemValue("ApprovedOn", mDt.toJavaDate());

Error while executing JavaScript action expression

Script interpreter error, line=168, col=17: [TypeError] Exception occurred calling method NotesDocument.replaceItemValue(string, Date) null

Please guide me how can I store current server date in a date and time field when any action is performed. Thanks for your time and efforts.

1
Are you sure myDoc is set correctly? The message said it's null. - Knut Herrmann
I think it's because NotesDocument.replaceItemValue(string, Date) doesn't exist as a method, so the method is null, not the document. - Paul Stephen Withers
@PaulStephenWithers Yes this is for both XPiNC and Web.Moreover the same function NotesDocument.replaceItemValue(string, Date) works well when is session.createDateTime(@Now()) and stores client date and time. - Qaiser Abbas

1 Answers

0
votes

AFAIK, SSJS can only run within the XPages runtime. For an XPages application accessed via a browser, the XPages runtime sits on top of the HTTP task on the server, so the date and time would be the server's. (That's why I asked the question above).

For setting a field value with the core Domino API, you need to pass a NotesDateTime. The NotesDocument SSJS class (mapping to the underlying Java Document class) doesn't allow you to pass a Java date. OpenNTF Domino API does allow you to pass a Java date and auto-converts the value.

Best approach for XPiNC (this came from Serdar Basegmez, I can't take credit) is access a server-based database in SSJS, call createDocument() method and access it's created date. In the getDatabase() method you'll have to explicitly name a server. This will have a performance impact, because XPiNC is running locally, so you're connecting from local to another server, but will work.