I’m trying to fill an existing valuelist with data and attach it to an existing field, of course without success. The error I get is this:
TypeError: Cannot set property “valuelist” of to “org.mozilla.javascript.NativeJavaObject@a56e72”
so I assume that there is a problem with the dataset.
history.removeForm('contacts_profile');
var form = currentcontroller.getName();
var myForm = solutionModel.getForm('contacts_profile');
var label1 = forms.general_cont_profiles.gs_cont_lable1;
myForm.newLabel(label1, 20, 86, 80, 20);
var field = forms.contacts_profile.cont_prof_field01;
var field1 = myForm.getField('field');
var valuelist1 = solutionModel.getValueList('cont_prof_field01');
var dataset = null;
var serverName = currentcontroller.getServerName();
var queryCom = "SELECT gs_cont_text FROM general_settings WHERE gs_cont_number = 01";
var values1 = databaseManager.getDataSetByQuery(serverName, queryCom, null, 100);
valuelist1.customValues = values1;
field1.valuelist = valuelist1;
forms.contacts.elements.tab_details.tabIndex = 2;
var field = forms.contacts_profile.cont_prof_field01;
var field1 = myForm.getField('field');
Don’t you mean:
var field1 = myForm.getField('cont_prof_field01');
To fill the valuelist, you can use application.setValueListItems(), see the sample code:
//do query and fill valuelist
var query = 'select c1,c2 from test_table';
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(), query, null, 25);
application.setValueListItems('my_en_types',dataset);
Don’t you mean:
var field1 = myForm.getField(‘cont_prof_field01’);
Yes, but shouldn’t be the same?
I tried your code, but the problem seems to be in:
field1.valuelist = valuelist1;
while debugging, as soon it reaches this line I get the error. To be clear, here is the new code
history.removeForm('contacts_profile')
var form = currentcontroller.getName()
var myForm = solutionModel.getForm('contacts_profile')
var label1 = forms.general_cont_profiles.gs_cont_lable1
myForm.newLabel(label1, 20, 86, 80, 20)
var field1 = myForm.getField('cont_prof_field01');
var dataset = null
var serverName = currentcontroller.getServerName()
var queryCom = "SELECT gs_cont_text FROM general_settings WHERE gs_cont_number = 01"
var dataset = databaseManager.getDataSetByQuery(serverName, queryCom, null, 100)
application.setValueListItems('cont_prof_field01',dataset);
var valuelist1 = solutionModel.getValueList('cont_prof_field01')
field1.valuelist = valuelist1
forms.contacts.elements.tab_details.tabIndex = 2
Nop, the field exists in the table but is not yet on the form.
I want to fill the field with values from the valuelist an then, depending of the type (combo, checks…) give him a position on the form. But probably my line of thoughts is a little weird.
A field in the solution model is a field on a form. It can have a database column as it’s dataprovider, but it is really something else. Does that make things clear?
The thing that goes wrong is that you try to attach a valuelist to a field that isn’t on the form.
It’s actually just like when you use the designer: You have to put the field on the form before you can attach a valuelist.