Making one combo box take notice of another one in XPages
Written by TimsterC on Thu 14-Jan-10 – 14:00 -Someone asked me yesterday if I could send them an example of how to have one combo box influence what appears in another combo box on the XPage. As I’ve been asked this before (several times) I thought I should write it up.
In this example I’m picking up values from lookup documents in a lookup view. They could be anything but I have used simpleĀ two field Notes form.
In your custom control or XPage drag two combo boxes onto the page.

Combo Boxes
In the first combo box I have bound it to the form that I want to store the data in. In this case it’s comoboboxtest with two fields on it.
For the Values I have used the following @formula
@DbColumn(@DbName(),”vwLookup”,1)
(note the capitalisation and commas)

Lookup formula
For the Events of this comobo box you need to click the onChange event (ServerSide) and then select partial refresh. In the dialog pick the other comob box that you dragged onto the page. Also you need to select the “Do not update or validate date” check box.

Event setting for Combo Box 1
Then in the second combo box bind it to the other field in your destination document.
For the values you need to add another formula.
var combo1 = getComponent(“comboBox1″).getSubmittedValue();
@DbLookup(@DbName(),”vwLookup”,combo1,2);
This sets the variable combo1 to the value that you have picked in the first combo box and then uses combo1 to lookup the values in your view. (Your view must be sorted for this to work and what you are looking up must be the first column)

values formula for Combo Box 2
The other important thing here is that you need to set this script to run dynamically instead of at page load.
And that’s it.
Download a small sample here. XPagesTesting
My thanks for Paul Hannan for helping me bug fix this with thousands of other things running through my head this morning.
Posted in XPages | 1 Comment »

February 25th, 2010 at 9:13
It is worth noting that if you need to check for both the submitted value and the “normal” value if the onchange event has not yet been fired – for example if you open an existing document or if the “correct” value has already defaulted in to the first box.
see the redbook example here
http://www-10.lotus.com/ldd/ddwiki.nsf/dx/Form_Design#Combining%20getValue%20and%20getSubmittedValue
and my post here
http://seancull.co.uk/Public/seancull.nsf/dx/SNTT-Examples-of-accessing-fields-on-Xpages
cheers, Sean