Search code examples
xpagesxpages-ssjs

view daterange , end date not correct


I'm selecting documents in a view by daterange. The start date is alway correct but the end date isn't. The selection goes from the startdate till the last entry. My code is :

var vDateRange = session.createDateRange(sessionScope.selectedStartDate, sessionScope.selectedEndDate);
var projects:NotesView = database.getView('visits_by_date_VB')
var viewNav:NotesViewNavigator = projects.createViewNav();
var viewEntryCollection:NotesViewEntryCollection = projects.getAllEntriesByKey(vDateRange);
var viewEnt:NotesViewEntry = viewEntryCollection.getFirstEntry();

var output:string = "";
while (viewEnt != null) {
 output += "<tr>";
 output += "<td>" + viewEnt.getColumnValues()[0]; + "</td>";
 output += "<td>" + viewEnt.getColumnValues()[3] + "</td>";
 output += "<td>" + viewEnt.getColumnValues()[4] + "</td>";
 output += "<td>" + viewEnt.getColumnValues()[5] + "</td>";
 output += "</tr>";
viewEnt = viewNav.getNext(viewEnt);
}

EDIT

Picking up dates with following code :

<xe:djDateTextBox id="StartDate"
                            defaultValue="#{javascript:sessionScope.selectedStartDate}"
                            value="#{sessionScope.selectedStartDate}">
                            <xp:this.converter>
                                <xp:convertDateTime type="date"
                                    dateStyle="full">
                                </xp:convertDateTime>
                            </xp:this.converter>
                        </xe:djDateTextBox>
       <xe:djDateTextBox id="EndDate"
                            defaultValue="#{javascript:sessionScope.selectedEndDate}"
                            value="#{sessionScope.selectedEndDate}">
                            <xp:this.converter>
                                <xp:convertDateTime type="date"
                                    dateStyle="full">
                                </xp:convertDateTime>
                            </xp:this.converter>
                        </xe:djDateTextBox>

First column of the view is a date /time "style" sorted Ascending The field on the form that stores the dates is a date time field .


Solution

  • Change this one line

    viewEnt = viewNav.getNext(viewEnt);
    

    to

    viewEnt = viewEntryCollection.getNextEntry(viewEnt);
    

    and it will work.

    You initialize viewNav with the complete view content. That's why it starts with the right date from viewEntryCollection but runs always to view's end. You don't need the viewNav in this code and can delete this line.