I have an HTTP process which retrieves the following JSON:
[{“account”:“1234567890”},{“account”:“1234567899”},{“account”:“1234567888”},{“account”:“1234567999”},{“account”:“1234567444”}]
I would like to list these accounts in a Dropdown on a form. Any idea what expression I should use as nothing seems to work.
In your process flow, after the Http Task add a Script Task with Groovy language. Then, try the following code:
//retrieve JSON response
final def response = execution.getVariable("yourResponseVariableWithJson");
//response must not be null and empty
if (response != null && response.toString().length() > 2) {
//array to store options in appropriate format
final def String options = "[";
//loop through JSON array
response.each {
//from each iterated object in array, get the account variable and add it to the options
options += '{"id":"' + it.account + '","name":"' + it.account + '"},';
}
//remove trailing comma
options = options.substring(0, options.length() - 1);
//close the array
options += "]";
//store options as a process variable
execution.setVariable("myDropDownOptions", options);
} else {
execution.setVariable("myDropDownOptions", "");
}
Then, you can reference the stored variable like this:
but the execution of the model is failing with below error
is the a specific data type needed for this variable other than string, if so how to declare it
org.flowable.common.engine.api.FlowableException: Error getting value for optionsExpression: ${myDropDownOptions}