Reputation: 703
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());
Upvotes: 0
Views: 5175
Reputation: 20384
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:
Upvotes: 4
Reputation: 366
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.
Upvotes: 0
Reputation: 3484
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.
Upvotes: 2
Reputation: 1413
Have you tried making the dblookup work outside of xpages, i.e. with ScanEZ or in the Notes client?
Upvotes: 2