Search code examples
datetimexpageslotus-noteslotus-dominoxpages-ssjs

XPages: create current Datetime in ssjs and save to a Datetime Notes form field


The only way i have found to store date in a Datetime field in a notes form is this:

theDoc2.replaceItemValue("lastAccess",session.createDateTime("Today"));

But this only creates a Date, not DateTime. Also, i dont want to create a static time like "Today 12" but i want the current datetime dynamicly.

Using this i get an error (Exception occurred calling method NotesDocument.replaceItemValue(string, Date) null):

theDoc2.replaceItemValue("lastAccess",@Now());

and using this, the form field changes from Date/Time to Text data type and i want to keep Date/Time type:

theDoc2.replaceItemValue("lastAccess",@Now().toLocaleString);

Any ideas?


Solution

  • Just gave it a try:

    as you wrote, .replaceItemValue("fieldName", @Now()) throws an error.

    However, I got it to work with

    .replaceItemValue("fieldName", session.createDateTime(@Now()))
    

    In that case the value is stored in the Notes field as Time/Date with all necessary components as in

    17.01.2014 12:45:51 CET
    

    From what I can see, difference between the two is that @Now() returns a Date data type, whereas session.createDateTime() returns a NotesDateTime object

    On the other hand, for me it's also working with your original method:

    session.createDateTime("Today")
    

    Don't know what's causing the prob on your side; do you have an editable represantion of the field on you xpage? If so, does it have some kind of converter enabled which could do some filtering during submit?