Monday, September 18, 2006

@NameLookup not returning multiple values ... so make it single value

These weeks I am developing a web interface for administrating Domino users. Web users. No fancy Domino Administrator, no Lotus Notes ID's, nothing of this sort. Just plain database with design inherited from pubnames.ntf, then add/modify design elements.

In this adventure I was inspired by the following great articles:
Bob's view navigation
Ferdy's Domino XHTML Forms

[I managed to get and use the view navigation from Bob's site, I also tweaked it according to the requirements. I hope that when finished, I will upload my work back to the community, in an empty template. A future article will follow on this subject.]

The issue I was facing is that @NameLookup apparently does not return a list of values, when the item I'm looking for is multiple-values. It only returns the first value. Why the hack is this happening I cannot tell.

Let me explain:

I do have a computed for display field (can be also a simple computed text) with the following standard formula:

user := @Name([CN] ; @UserName);
lookup:= @NameLookup ([Exhaustive]; user ; "OfficeCountry");

No error checking as to keep it simple. As you see, I am trying to return the OfficeCountry Domino item. By default, this is a single value field in pubnames.ntf design. Ehh, so what, I've made it multiple values in my web form, also in $PersonInheritableSchema subform which is used to display the document in Notes.
I had no luck: even though values are displayed as list in the OfficeCountry field, only the first value is returned when I do the @NameLookup.

Feel free to drop me an email if this works for you, it didn't for me. And I don't have to worry about it because I managed to trick the damn thing.

Obviously I had to drop the idea of making OfficeCountry as multiple value field, instead I made a trick, described here. The idea through me off my chair due to its simplicity:

The HTML code in my web form is the following:
<select name="OfficeCountrySelect">


<input name="OfficeCountry" value="" type="hidden">

Then, just before doing the submit() so that changes are saved, we do some validation (Carefully read and understand Ferdy's article above, it explains it very well) and I simply take all options values and put them into the OfficeCountry hidden field, with a JS code some something like:

//validation function body
if (document.all) document.all.OfficeCountry.value = _
getOptionsFromSelect ('OfficeCountrySelect') ;
//validation function body

then comes the getOptionsFromSelect function:

function getOptionsFromSelect (strObj) {
selected = new Array();
var obj = document.getElementById (strObj) ;
for (var i = 0; i < obj.options.length; i++)
if (obj.options[ i ].selected) {
selected.push (obj.options[ i ].innerText);
return selected.toString ()

And here we go, the OfficeCountry will store a single value: Country1,Country2,Country3
Then, @NameLookup will return all values as a single string and I don't need to worry about it returning only single values.
Obviously, in other parts of the code, I need to @explode this string so that I can work with it.
Post a Comment

Disclaimer: The information in this weblog is provided "AS IS" with no warranties whatsoever, and confers no rights to any institution/person/organization. These are my personal thoughts and ideas. When I am inspired by others I give credit, I do not assume other's work and efforts. This site is NOT supported, approved, blessed etc. by Lotus Software and/or IBM Corporation.

Creative Commons License

This work is licensed under a Creative Commons Attribution 3.0 License.