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

Xpages - getNextDocument() not accessing a Date field


The reason for the above error is because the 'FinishDate' field is empty, which is understandable. What I have been trying to do in the loop is replace any empty 'FinishDate' field with today's date.

'FinishDate' will be continuous until the activity has properly ended and that is when endDate will be generated and the 'FinishDate' field will be populated in the document.

I tried the below which works while looping through just the NotesDocument, but doesn't with NotesDocumentCollection:

               try {
                    var endDate:NotesDateTime = null;
                    if(!docEv.getItemValue("FinishDate").isEmpty()){
                        endDate = docEv.getItemValue("FinishDate").elementAt(0);
                    }else{
                        endDate = session.createDateTime(@Now());
                    }
                }catch(e){
                    print("endDate: " + e.toString())
                }   

The 'else' statement is skipped each time it runs.

Below is the full code and the error block.

function getCalObj(){   
var viewEv:NotesView = database.getView("Diary");
var doc:NotesDocument = diaryDoc.getDocument();
var sUNID = doc.getUniversalID();
var dcEv:NotesDocumentCollection = viewEv.getAllDocumentsByKey(sUNID);
if(dcEv.getCount() != 0){
    var docEv:NotesDocument = dcEv.getFirstDocument();          
    var calendarData = '';      
    try {
        while (docEv != null) {
            var pattern = new java.text.SimpleDateFormat("yyyy-MM-dd"); 
                try {
                    var calDate:NotesDateTime = docEv.getItemValue("QueryStartDate").elementAt(0);
                }catch(e){
                    print("calDate: " + e.toString());
                }
                try {
                    var endDate:NotesDateTime = null; //check if date is empty
                    if(!docEv.getItemValue("FinishDate").isEmpty()){
                        endDate = docEv.getItemValue("FinishDate").elementAt(0);
                    }else{
                        endDate = session.createDateTime(@Now()); // if endDate is null replace with todays date
                    }
                }catch(e){
                    print("endDate: " + e.toString())
                }                   
                try{
                    .........
                }catch(e){
                    print("Cal data error" + e.toString());
                }                           
            var tmpdocEv = viewEv.getNextDocument(docEv);
            docEv.recycle();
            docEv = tmpdocEv;
        }
    } catch(e) {
        print("DocEv Loop Error: " + e.toString()); //error, read below
        //DocEv Loop Error: Exception occured calling method NotesView.getNextDocument(lotus.domino.local.Document)
    };
};

}

Your help will be appreciated.


Solution

  • You are looping through a NotesDocumentCollection but you use getNextDocument on the view and not the document collection. So change your line with getNextDocument to this:

    var tmpdocEv = dcEv.getNextDocument(docEv);