Nov 28, 2013 3:51 AM
93 Posts

Doc Collection / View Entry Collection .getCount()

  • Category: Server Side JavaScript
  • Platform: Windows
  • Release: 8.5.3
  • Role: Developer
  • Tags: getCount()
  • Replies: 4

Hi guys,


I am getting a document collection based on an array / vector and then counting the number of docs in the collection.

It works when I only have documents where the first column has the same values, but as soon as there are different values in the first column count always returns 0.

Another team member mentioned he had seen a problem like this before and had to get the last doc in the collection first, so I tried this to no avail.

I then tried a viewEntryCollection, getLastEntry and while entry !=null loop through  using GetPrevEntry and adding 1 to the count each time, however it never gets into this while loop.

Any idea's on how to get a count of documents? The key I am using is date and title. In the view the date column is sorted as is the title column.




Here is my current code with the viewEntry (you can see some commented out code for my doc coll also thats still there)


writeToLog("Starting quantity default value...");
var v:NotesView = database.getView("VProductLoanRequests");
var query = new java.util.Vector();
//Get the current date value in the date from field and product title
var date:NotesDateTime = getComponent("edtProductLoanRequestDateFrom").getValue();
if (date == null){
return sessionScope.itemQuantity
var productName:NotesDateTime = getComponent("edtProductLoanRequestName").getValue();
var dateKey:string = date.toString().substring(0,8);
writeToLog("DATE: " + dateKey);
writeToLog("NAME: " + productName);
//Add these values into an array to use as lookup key
//Get a document collection from the key, and count the amount of documents
//var dc:NotesDocumentCollection = v.getAllDocumentsByKey(query); OLD
var dc:NotesViewEntryCollection  = v.getAllEntriesByKey(query);
//var doc:NotesDocument = dc.getLastDocument();OLD
var count:integer = 0;
var entry:NotesViewEntry = dc.getLastEntry();
while (entry != null) {
count = count+1
var tmpentry:NotesViewEntry = dc.getPrevEntry(entry);
entry = tmpentry;
//var count:integer = dc.getCount().toFixed();
writeToLog("Count = " + count);



Nov 28, 2013 5:09 AM
93 Posts

Ignore this, it now seems to be working, where as it didnt yesterday


Possibly index issue?


Im not going to change my code back to a doc coll as its working with viewentry, but any ideas where the count of a doc collection was always returning 0?



Nov 28, 2013 9:11 AM
366 Posts
I'm curious...

as to why you would process the entire collection to get a count instead of just calling the methods that return the count.  All of the collection objects have one.

Nov 29, 2013 9:45 AM
93 Posts

Hey Paul,

Are you asking why I dont simply use dc.getCount().toFixed();??


If so, then this is my problem, it is always returning 0, unless there is only 1 category of document in the view, then it counts correctly. (Similarly with an entry collection)


If I have misunderstood what you mean, let me know :- )




Dec 12, 2013 12:10 PM
453 Posts
I have had something like that happen to me.

I have a custome control with this code in the before Load event:

try {
var doc:NotesDocument = database.getProfileDocument("frmConfigProfile","");
var repID:string = doc.getItemValue("WFSHelpRepID")[0];
} catch(e) {
    viewScope.put("vsStatus","Could Not Locate frmConfigProfile");

I had been working fine for a fair wile. Then it started returning the message ,"Could Not Locate frmConfigProfile" even though the Profile was there, I opened it using LS and also edit it. After more time than I want to admit, and changing where I executed this code, I went back to the original code (which I had saved before starting all of this). Tried it and it came back with the same messasge - BTW there were no errors reported in the custom control or the XPage that displayed it. I gave up closed the designer and Notes Client (for about the 4th time) and went and had a coffee and a deep breath. Came back opened Notes, opened Designer tried the Xpage that contains the cc and it started to work.

Some time strange things happen.