This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Feb 24, 2012, 7:48 PM
4 Posts

Display number of documents in a view for a date using xpages

  • Category: Server Side JavaScript
  • Platform: All
  • Release: 8.5.3
  • Role: Developer
  • Tags: dblookup
  • Replies: 2
 Hi.

I'm trying to get a basic xpage to show totals for completed cases from a number of product databases.  This is the JavaScript value of a computed field on a custom control:

var db = new Array(@DbName()[0], 'otherdatabase.nsf')

var today = new Date();
var yr = today.getFullYear().toString()
var mth = (today.getMonth()+1).toString();
if(mth.length == 1){
mth = "0" + mth
}
var dy = today.getDate().toString();
if(dy.length == 1){
dy = "0" + dy
}
var KEY = yr+mth+dy;

completed = @DbLookup(db, VIEW, KEY, 2);

if (completed != null){
@Elements(@Trim(@Explode(completed)));
}
else
{
return 0;
}

This looks up a view that has the first categorised column that does match the data value.  The idea is that I should be able to look up the completed cases for any given date eventually.

However it is only ever returning 0.

By comparison the computed text on a form as follows works perfectly:

TEXT := "Product 1";
DBFILE := "otherdatabase.nsf";
SERVER := @Subset( @DbName; 1 );
DIR := @Left(@Subset( @DbName;-1 ); "\\" );
DIR := @If( @Contains( @LowerCase(DIR); "dev" );
"ncidev"; @Contains( @LowerCase(DIR); "test" );
"ncidev"; "instruction" );
DBASE := DIR + "\\" + DBFILE;
VIEW := "lookupcompletedbydate";
yr := @Text(@Year(@Today));
mth := @Text(@Month(@Today));
theMonth := @If(@Length(mth) = 1; "0" + mth; mth);
dy := @Text(@Day(@Today));
theDay := @If(@Length(dy) = 1; "0" + dy; dy);
KEY := yr+theMonth+theDay;
VAL := @DbLookup( "":""; SERVER: DBASE; VIEW;KEY; 2 );
VAL := @Elements( VAL );

TEXT + ": " + @Text(VAL)

What am I doing wrong?
Feb 27, 2012, 8:31 AM
261 Posts
Re: Display number of documents in a view for a date using xpages
Try to find out on what line your code fails. Are you sure that the database/ view/ documents are accessible from your XPage?
 
Also a couple of remarks about your code:
  • @DbLookup in XPages returns an string if it finds 1 result or an array if it find more results. I'd suggest to first always convert the result to an array and then count the number if items:
var completed = @DbLookup(db, VIEW, KEY, 2);
if (typeof completed == "string") { completed = [completed]; }
 var nrItemes = completed.length;
  • To get a date formatted as yyyymmdd you might also want to check out the SimpleDateFormat Java class.
Feb 27, 2012, 8:48 AM
4 Posts
Re: Display number of documents in a view for a date using xpages
 There's a reason why I shouldn't try coding on a Friday evening.
 
I stupidly missed the view name .
 
var db = new Array(@DbName()[0], 'mydatabase.nsf')
var VIEW = "lookupcompletedbydate";
var today = new Date();
var yr = today.getFullYear().toString()
var mth = (today.getMonth()+1).toString();
if(mth.length == 1){
mth = "0" + mth
}
var dy = today.getDate().toString();
if(dy.length == 1){
dy = "0" + dy
}
var KEY = yr+mth+dy;

completed = @DbLookup(db, VIEW, KEY, 2);

if (completed != null){
@Elements(@Trim(@Explode(completed)));
}
else
{
return 0;
}
 

This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal