Alvinmactal,
As Andrea mentions, it is recommended to use SQL to populate the list of options in a dropdown box from a PM Table or external database. Alternatively, you can use an
array variable created in a trigger to populate the list of options.
However, if you really want to do it in with JavaScript in a BPMN process in PM 3 and later, then you can use this code:
$('#dropdown_id').getControl().append( new Option(newLabel, newKey, defaultSelected, nowSelected) );
For example:
Code: Select all$('#selectService').getControl().append( new Option("Accounting", "accounting", false, true) );
The problem will dynamically adding options to a dropdown is that if that if the Dynaform needs to be displayed a second time to the user (or a Process Supervisor), then any added options will be lost and the user won't be able to see the selected option if it was added with JavaScript.
The way to get around this problem is to store the added options in a JSON string in a hidden field and add the stored options to the dropdown when the DynaForm is displayed again. To see an example how to do this with JavaScript, import the attached DynaForm which can be displayed multiple times without problems.
(6.22 KiB) Downloaded 35 times
Amos B. Batto ♦ ProcessMaker Forum Manager since 2009
Workflow Customized!