0
votes

I have an XPage that is doing an @DbLookup with a user's input and trying to find that value in a view in a different database yet on the same server.

I have already verified that the view is in fact sorted by the first column and therefore @DbLookup friendly. The following code below appears in the server-side Javascript OnClick event handler for a button on my XPage.

My problem is that the an error occurs when trying to assign the value of lRep to the 'firstNameLabel'. lRep is returning a null value from the dbLookup even though the a record under the 'FirstName' field exists with the key 'P301993'. This dbLookup should be finding a returning a single 'FirstName' result. However, it is not.

var resultLabel = getComponent("firstNameLabel");
var dbName = new Array(@DbName()[0],"UKCSandbox.nsf");
var lRep = @DbLookup(dbName,"customerLookup","P301993","FirstName");
resultLabel.setValue(lRep.toString());
4
I think the code should like lRep = (typeof lRep == "string") ? "No result" : lRep;. Have you missed assigning lRep value in actual code or the one reproduced here?Naveen
No that didn't work. The issue is that the dbLookup is not working. It is producing an error.user1546315
What error are you getting?Toby Samples
Toby it's hard to describe the error since I really don't have any debugging informaion with it being server-side javascript. When I tried to run the code and have it output the value of lRep into a label I got a 'Webiste cannot display this page' error in the web browser. This is incredibly frustrating.user1546315
To get a more specific error turn on "Display Xpage runtime error page" in Application properties.Toby Samples

4 Answers

4
votes

Unless your formatting was lost in copy and paste, your code has flaws. This is not Java, this is JavaScript. Line endings matter and functions don't act on the object, but return a value. Also @DbLookup returns a string when you have exactly one match, so checking for string doesn't help you.

Your code should look like that:

var ukcNumber = Registration.getItemValueString('UKCNumber').toUpperCase();
var resultLabel = getComponent("ukcNumberLabel");
var dbName = @DbName();
dbName[1] = "UKC\\UKCSandbox.nsf";

var lRep = @DbLookup(dbName,"customerLookup",ukcNumber,1);

resultLabel.setValue((lRep) ? "Success" : "Failed");

Does that work for you?

Update: 2 things to check:

  • does the lookup work in the same database using @DbName?
  • XPages have the same security constraints as Java agents. Do you have enough rights in the server document to do a 'get value from other database'? Default is No!
2
votes

Have you tried making the dblookup work outside of xpages, i.e. with ScanEZ or in the Notes client?

2
votes

Check your ukcNumber variable so it contains a value.

Edit

Check so the user has rights to do the lookup in the other database. Also try a similar code on an old Notes Form and see if you get the same result.

0
votes

Why can't you use keyword '[FAILSILENT]' in your @DBLookup call. It'll return "", if no entry matches with your key. If you still have issues, use SSJS/java code to see where it's breaking up.