Attach a valuelist in code

Hi,
Is there a way to attach a valuelist to an existing field from within my code?

Can someone please give a code example of how to do this?

Regards
Hareendra

You can use the solution model to do that:

var _form = solutionModel.getForm(myForm);
var _field = _form.getField(myField);
_field.valuelist = myValuelist;

Note that this only changes the “blueprint” of the form, if you showed or touched the form before, you have to call history.removeForm(myForm) first.

Another option might be to change the contents of the valuelist, take a look at the sample of application.setValueListItems();

Hi Joas,
I tried using the valuelist with the solution model as you suggested. But, it doesn’t get attached.
My code is as follows:
var _form = solutionModel.getForm(‘frm_test_main’);
var _field = _form.getField(‘field2’)
_field.valuelist = solutionModel.getValueList(‘lst_test’);
_field.displayType = SM_DISPLAYTYPE.COMBOBOX;

The form frm_test_main is an existing one. And the field ‘field2’ is the name of the field that I want to attach the valuelist to.

Executing this code doesn’t result in anything. It runs through without an error.

Regards
Hareendra

But have you showed or touched that form in code before? Because then you have to remove the form from the history, like I said.

If you’re looking at the form when the method is triggered, you need to “unshow” it, remove it from history, make the change and then show it again, like this:

	forms.other_form.controller.show();
	history.removeForm("frm_test_main");
	var _form = solutionModel.getForm("frm_test_main");
	var _field = _form.getField("field2");
	_field.valuelist = solutionModel.getValueList("lst_test");
	_field.displayType = SM_DISPLAYTYPE.COMBOBOX;
	forms.frm_test_main.controller.show();

Showing the other_form in between will happen so fast, that it will be hard to even notice.