Programmatic assignment of valuelists?

I have an “included” list displaying related many records. One of the related many fields should have a valuelist attached. However, each of these records should have a different valuelist attached to the same field, depending on the record type (contents of another field, “category”). So I need to assign the valuelist on the fly, either as the records are displayed or as the user clicks on the field to which the valuelist is assigned.

Is this possible in Servoy? So far I haven’t found a command to procedurally assign an existing valuelist (I’ve created these already, they are based on querying a “choice_list” table).

Thank you,
Don

First of all, assign a “dummy” value list to the field in question and then when you click on a specific record, modify the contents of that value list based on the record category (application.setValueListItems(…)). In other words, don’t change the field’s value list, change the contents of the current value list.

There is a gotcha that you need to handle: when a field has a value list attached and the field value is not in the value list, a blank is displayed instead of the field value (the exception is editable comboboxes). So as you dynamically change the value list per record selected in a list/table view, it is quite likely to have values in that column on surrounding records “disappear”.

Recently Servoy added a “Fallback Valuelist” option (bottom left of the value list editor). Using this, create another “master” value list that has all of the field options possible and assign this value list as the fallback value list to the above dummy value list.

First of all, assign a “dummy” value list to the field in question and then when you click on a specific record, modify the contents of that value list based on the record category (application.setValueListItems(…)). In other words, don’t change the field’s value list, change the contents of the current value list.

There is a gotcha that you need to handle: when a field has a value list attached and the field value is not in the value list, a blank is displayed instead of the field value (the exception is editable comboboxes). So as you dynamically change the value list per record selected in a list/table view, it is quite likely to have values in that column on surrounding records “disappear”.

Recently Servoy added a “Fallback Valuelist” option (bottom left of the value list editor). Using this, create another “master” value list that has all of the field options possible and assign this value list as the fallback value list to the above dummy value list.

Thank you David, I will check it out. - Don

I have a similar problem. I am trying to refresh the valuelist each time a value is selected in the previous combobox (see image). You would pick a department from available departments within a selected lab. Then you would pick an instrument from available instruments within the selected department, etc. I am using setValueListItems, but the valuelist isn’t refreshing with the limited list.

[attachment=0]DataEntry1.jpg[/attachment]

Here is the code I am using:

function update_department_list() {
	var mylab_id = globals.selected_lab_id;
	var server = 'medlabqcpro_hr'
	var query = "select code, department_id from tbl_department where laboratory_id = " + "'" + mylab_id + "'"
	var dataset = databaseManager.getDataSetByQuery(server, query, null, 25);
	var idArray = dataset.getColumnAsArray(1);
	var nameArray = dataset.getColumnAsArray(2);
	application.setValueListItems('d_departments',nameArray, idArray)
}

The dataset and values are being pulled out correctly. It is just that the valuelist isn’t being updated. I have tried this on different events (onDataChange, onRecordSelect, etc). I have also tried using just dataset and also splitting the dataset into arrays, like I did above. What am I missing?

Cheers!

Ray

Can’t see anything wrong with your code. Try putting in an application.updateUI() call at the end.

Hi,

We went already that way. There is some Servoy caching going on bound to the real value of the dataprovider.
Suppose the real value of the not updated valuelist is null, then the following code does the tric :

dataprovider = -1
dataprovider = null

and voilà : the valuelist is updated in the UI dropdown.

A nicer Servoy solution would be appreciated… :?

Regards,

Problem fixed. Thanks for your help!