Programmatic assignment of valuelists?

Questions, tips and tricks and techniques for scripting in Servoy

Programmatic assignment of valuelists?

Postby djlapin » Fri May 20, 2011 2:22 am

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
djlapin
 
Posts: 309
Joined: Fri Feb 18, 2011 9:36 am
Location: San Francisco, CA

Re: Programmatic assignment of valuelists?

Postby david » Fri May 20, 2011 8:32 pm

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.
David Workman, Kabootit

Image
Everything you need to build great apps with Servoy
User avatar
david
 
Posts: 1727
Joined: Thu Apr 24, 2003 4:18 pm
Location: Washington, D.C.

Re: Programmatic assignment of valuelists?

Postby david » Fri May 20, 2011 8:33 pm

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.
David Workman, Kabootit

Image
Everything you need to build great apps with Servoy
User avatar
david
 
Posts: 1727
Joined: Thu Apr 24, 2003 4:18 pm
Location: Washington, D.C.

Re: Programmatic assignment of valuelists?

Postby djlapin » Mon May 23, 2011 3:46 am

Thank you David, I will check it out. - Don
djlapin
 
Posts: 309
Joined: Fri Feb 18, 2011 9:36 am
Location: San Francisco, CA

Re: Programmatic assignment of valuelists?

Postby rgerz » Tue Jun 14, 2011 7:31 pm

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.

DataEntry1.jpg
DataEntry1.jpg (45.9 KiB) Viewed 4706 times


Here is the code I am using:

Code: Select all
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
rgerz
 
Posts: 15
Joined: Mon Jul 20, 2009 11:18 pm

Re: Programmatic assignment of valuelists?

Postby david » Tue Jun 14, 2011 7:53 pm

Can't see anything wrong with your code. Try putting in an application.updateUI() call at the end.
David Workman, Kabootit

Image
Everything you need to build great apps with Servoy
User avatar
david
 
Posts: 1727
Joined: Thu Apr 24, 2003 4:18 pm
Location: Washington, D.C.

Re: Programmatic assignment of valuelists?

Postby lwjwillemsen » Tue Jun 14, 2011 8:06 pm

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,
Lambert Willemsen
Vision Development BV
lwjwillemsen
 
Posts: 680
Joined: Sat Mar 14, 2009 5:39 pm
Location: The Netherlands

Re: Programmatic assignment of valuelists?

Postby rgerz » Wed Jun 15, 2011 6:31 pm

Problem fixed. Thanks for your help!
rgerz
 
Posts: 15
Joined: Mon Jul 20, 2009 11:18 pm


Return to Methods

Who is online

Users browsing this forum: No registered users and 6 guests