Search code examples
xpageslotus-notesxpages-ssjsdomino-designer-eclipsessjs

Xpages - Exception occurred calling NotesDocument.getItemValueDateTimeArray(string)


I have built an xpages application using full calendar and so far able to display data on the calendar. But whenever any of submitted field is left blank, it kills the calendar page and returns the exception error above. If no blanks in the submitted fields, the calendar opens nicely.

I could have resolved this issue by using validation on the form to ensure that all fields are filled in, but this will restrict users and I want to avoid this.

Below is the code returning the error:

try { 
  var calendarDate:NotesDateTime; 
  try{
    calDate:NotesDateTime = docEv.getItemValueDateTimeArray("MeetingDate").elementAt(0);//error coming from here when it is null
  }catch(e){
      print("Meeting date null error: " + e.toString());
      return calendarDate;
  }
  if(calDate != null){
      var today:NotesDateTime = session.createDateTime("Today");

      if (calDate != null && calDate.timeDifference(today) > 0) {
          try{
              var calDate:NotesDateTime = docEv.getItemValueDateTimeArray("MeetingDate").elementAt(0);
          } catch(e) {
              print("calendar error: " + e.toString());
          }
      }
   }
  }catch(e){
      print("Calendar error: " + e.toString());
      return calendarDate;
  }

I also tried using the try/catch to stop the killing of the page, but that does not seem to work either.

Is there any logic I can use to check if var calendarDate:NotesDateTime; is null and if null to do nothing?

Many thanks.


Solution

  • Test if document has an item "MeetingDate" with at least one element:

    var calDate:NotesDateTime;
    if (!docEv.getItemValue("MeetingDate").isEmpty()) {
        calDate = docEv.getItemValueDateTimeArray("MeetingDate").elementAt(0);
        ...
    }