user3659403
user3659403

Reputation: 61

how to set value field in xpages from dblookup result?

I have Xpages with fields: Name & Level

The Name value set from formula: @Name("[ABBREVIATE]",session.getEffectiveUserName());

And i want to set field Level using @DbLookup that query to MasterDB.nsf

The problem is: I have put script on default value of the field Level, but it does not work. This is the script:

db = new Array(@DbName()[0], 'MasterDB.nsf');
var result = @DbLookup(db, "Person", document1.getItemValueString("Name"), 2);
result

How to solve the issue?

Upvotes: 2

Views: 720

Answers (1)

Knut Herrmann
Knut Herrmann

Reputation: 30960

document1.getItemValueString("Name") doesn't work in your case as the item "Name" in document1 is only set after a submit. So, it is "too early" to access the item "Name" in document1.

You could access the value of XPages element "Name" with getComponent("inputTextName").getValue() but in your case it is easier to calculate the effective user name again in Level's defaults code:

var db = new Array(@DbName()[0], 'MasterDB.nsf');
var username = @Name("[ABBREVIATE]",session.getEffectiveUserName());
var result = @DbLookup(db, "Person", username, 2);
return result;

Upvotes: 2

Related Questions