I have this function that loads the valuelist for a combobox. How do I get the selected id value from the combo so I can set a variable with it.
function refreshStateList()
{
var maxReturedRows = 60;
var query = ‘select stateName, StateID from tbl_states’;
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(), query, null, maxReturedRows);
var nameArray = dataset.getColumnAsArray(1);//put 1st column in array
var idArray = dataset.getColumnAsArray(2);//put 2nd column in array
I have not looked at your code (little impatient tonight) but the id is what should be returned to the field (type combo in your case) and attached dataprovider.
So, at the onDataChange event you can get the value from the dataprovider.
You are using, what I call, a 2 column value list. This means it contains a display value (column 1) and a real value (column 2).
You see and select the display value but the real value (the ID in this case) gets stored in the dataprovider that has this combobox.
So if your dataprovider is already that global variable you want to set then you are already done.
Or else you can do, like Marcel already suggested, use an onDataChange event on that field to set the variable you want with the stored ID.
Ok I used this to create the valuelist for the combobox which is fired on form load
function refreshStateList()
{
var maxReturedRows = 60;
var query = ‘select stateName, StateID from tbl_states’;
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(), query, null, maxReturedRows);
var nameArray = dataset.getColumnAsArray(1);//put 1st column in array
var idArray = dataset.getColumnAsArray(2);//put 2nd column in array
application.setValueListItems( “stateList”, nameArray , idArray )
}
Combobox name = cb_selectState
In an attempt to “see” the values selected I used this
function showValueList()
{
plugins.dialogs.showInfoDialog( ‘test’,forms.frm_JursList.elements.cb_selectState , ‘OK’)
}
This produced a popup
DataComboBox[cb_selectState:null:60]
60 IS the id I want to assigned to globals.stateIdSelected
You do need to add a dataprovider to that field. Right now it’s null.
Just add the globals.stateIdSelected as dataprovider and you can loose the whole onDataChange method altogether.
I am not sure what/why you do it like this but I have the idea you make your life much more difficult than necessary.
You can define the valuelist so that it is generated automatically for you.
You can hook up the list to the combobox without scripting.
You can attach the global var to that combobox
When you do so the selected value will automatically end up in that global var.
Maybe it is me but I miss the point about your dialog…
Ok I’m working through you method. I was working with the script to load values to the valuelist because it was updating my data in the underlying table. I found ‘editable’…
They are forced to move my first solution in Servoy4.1.
Because in Servoy 3.5.7 three combobox do not work in the same line in tableview. After weeks of hard job I have found three combobox they work alone on new release the 4.1.
Example, when mouse to go on other line :
-First combobox name-category, id-category, choose new category item= all right!
-Second combobox name-family, id-family, choose new family item= KO! If category is different, Servoy insert previously line selected combobox name family.
-Third combobox name-item, id-item, choose new item= KO! If family is different, Servoy insert previously line selected combobox name item.
In both cases, Servoy “feels” that it is changed the field and run the method onDataChange!
To go to Servoy 4.x !!!
Windows XP
Java 11.0
Servoy 3.5.7