Reputation: 21
I want to use a comboBox to display several locations. All locations are stored in a view. I want to have the default location to be displayed = location of the user in the person document in domino directory. My problem is, the default value does not apply to the comboBox, but is correct if I display it in a computed field. If I hardcode a value as default it works.
Here is my code:
<xp:text escape="true" id="computedField1">
<xp:this.value><![CDATA[#{javascript:viewScope.get("UserLocation")}]]></xp:this.value>
</xp:text>
<xp:this.beforePageLoad><![CDATA[#{javascript:var sUserName:string=@Name("[ABBREVIATE]",@UserName());
var sServer:string=session.getCurrentDatabase().getServer();
if (sServer!=null)
{
var nDb:NotesDatabase=session.getDatabase(sServer,"names.nsf");
if (nDb!=null)
{
var vUser:NotesView=nDb.getView("($VIMPeople)");
if (vUser!=null)
{
var docUser:NotesDocument=vUser.getDocumentByKey(sUserName,true);
if (docUser!=null)
{
var sLocation:string=docUser.getItemValue("Location");
viewScope.put("UserLocation", sLocation);
}
}
}
}}]]></xp:this.beforePageLoad>
<xp:br></xp:br>
<xp:comboBox id="comboBox1">
<xp:this.defaultValue><![CDATA[#{javascript:viewScope.get("UserLocation")}]]></xp:this.defaultValue>
<xp:selectItems>
<xp:this.value><![CDATA[#{javascript:@DbColumn(@DbName(),"Standorte",1)}]]></xp:this.value>
</xp:selectItems>
</xp:comboBox>
<xp:br></xp:br>
<xp:comboBox id="comboBox2" defaultValue="Hamburg">
<xp:selectItems>
<xp:this.value><![CDATA[#{javascript:@DbColumn(@DbName(),"Standorte",1)}]]></xp:this.value>
</xp:selectItems>
</xp:comboBox></xp:view>
The view Standorte has cities in the first column, sortet ascending: Berlin, Frankfurt, Hamburg,... The value in the users Person document is Frankfurt.
Output in the browser is: The computedfield1 displays Frankfurt (as expected) the ComboBox1 displays Berlin (the first value - not the computed default) the ComboBox2 displays Hamburg (as expected, because of hard coded default value)
Any suggestions what is wrong with the code?
Upvotes: 2
Views: 1489
Reputation: 1632
There are a few things I would do to make this work:
First: Make sure the viewScope entry for UserLocation is a string not a vector. Use getItemValueString() instead of getItemValue();
if (docUser!=null) {
var sLocation:string=docUser.getItemValueString("Location");
viewScope.put("UserLocation", sLocation);
}
Second: Make sure the UserLocation is part of the combobox pick list even if it does not exist in the lookup:
var list = @DbColumn(@DbName(),"Standorte",1);
list.push(viewScope.get("UserCompany"));
return @Unique(list);
Finally I would also make sure the user is not "Anonymous" and perhaps trap the session.getDatabase() in case there is an access issue to names.nsf.
if(sUserName == "Anonymous") return;
try {
var nDb:NotesDatabase=session.getDatabase(sServer,"names.nsf");
} catch(ex) {
return; // something went wrong opening the directory.
}
Happy coding.
/Newbs
Upvotes: 2
Reputation: 1667
Please check the following
Upvotes: 0