I’m creating a NotesDocument in SSJS, using doc.replaceItemValue, but I can’t seem to setting a date field. 've tried doc.replaceItemValue(“fldCreatedOn”,@Today()) but it throws an error. Unusually, the error message is null.I have the same problem with @Now or @TextToTime(@Text(@Today())).
It seems like replaceItemValue cannot cope with a date/time value (despite the Help saying it can). And it doesn’t seem to be throwing a valid error.
Has anyone got it to work?
Subject: Try Date()
Paul, try wrapping it in Date():
Date(@Today())
That forces the result to be treated as a JS date (which, in SSJS really means it’s treated as a java.util.Date at the point where it’s actually writing it to the item value), which should allow replaceItemValue to store the correct data type. If that doesn’t work, wrap the whole thing in session.createDateTime and then you’re working with true Domino date objects, not JS/Java approximations of the same value.
Subject: Date() works
Thanks Tim, Date() works fine. I think I’ll leave the finer points about what data types @Now, @Today and others produce and what replaceItemValue expects. I’ll just mark this down as something to remember.
Subject: Date() works, but…
It sets the notes item as text unless compute with form is used and the item is defined on the form as Date\Time.
Using NotesDateTime gives the desired result without further manipulation…
doc.replaceItemValue(“fldCreatedOn”, session.createDateTime(“Today”))