XPages Tip: Setting a Date Field with @Now
I came across an interesting quirk recently when using @Now() to set date fields in an XPages workflow application — it works on the front-end (XSP) document but not on a back-end NotesDocument.
Assuming I have a document data source named document1, this code will work in SSJS to set a date field to @Now() via the XSP document:
However, if I get the back end document and try to do the same thing, it throws an error. (The same is true if working with the back-end document even without getting a handle to it through the front-end document.)
Looking through the stack trace, this is the real error: “NotesException: Unknown or unsupported object type in Vector”
So it appears that the NotesDocument version of replaceItemValue() doesn’t handle that type of date.
Fortunately, there’s an easy workaround. You can use session.createDateTime() to get a date in a format that replaceItemValue can handle.
This line of code works: