Search code examples
datevectorxpagesxpages-ssjs

What is the correct way to read the value from a date field in Xpages using SSJS


I have a date field in a notes document and need to read the value using ssjs. if the field contains a value I can read it using

doc.getItemValueDateTimeArray[0]

but if the date field is empty the code will return an error.

so my question is how do I read a date field correctly using SSJS so that it does not return an error if it is empty and return a date value if there is a date value in the field

I am hoping for a solution without the need of a try/catch.

Thanks Thomas


Solution

  • Try something like this

    var item:NotesItem =doc.getFirstItem("ItemName");
    if (item== null) {
        dateVar=now;
    } else {
        dateVar=doc.getItemValueDateTimeArray[0];
    }