Multiple REST requests based on JSON array

Hi Thorben,

I"m trying same thing as in Multiple REST requests based on JSON array, but not able to do.
code sample:

  List<String> urls = new ArrayList<String>();
  urls.add("http://un-vm-0494.eu.uis.com/ingestion_db/travel_instances/2017-09-10_BR-0316_TR5BE794");
  urls.add("http://un-vm-0494.eu.uis.com/ingestion_db/travel_instances/2017-09-15_VA-0029_CA54370F");

  execution.setVariable("urls",  
		  Variables.objectValue(urls)
		    .serializationDataFormat(SerializationDataFormats.JSON)
		    .create());

and then using the urls to call multiple GET Requests.
setting url to a script ${urls.elements()} in http-connector of service task.

Pls let me know what I’m doing wrong. thanks in advance

Hi @bharath_kumar,

Please post the corresponding BPMN model and the stacktrace of the failure.

Cheers,
Thorben

Example_demo.bpmn (5.0 KB)
Appreciate the Quick response :+1:

2017-09-19 12:11:47,026 ERROR [org.camunda.bpm.engine.context] (default task-6) ENGINE-16004 Exception while closing command context: Unknown method used in expression: ${urls.elements()}. Cause: Cannot find method elements with 0 parameters in class java.util.ArrayList: org.camunda.bpm.engine.ProcessEngineException: Unknown method used in expression: ${urls.elements()}. Cause: Cannot find method elements with 0 parameters in class java.util.ArrayList

The configuration of the multi-instance activity is not entirely correct. The “element variable” property is the name of the variable that each element of the loop collection is assigned to. So if you loop over urls, url would be a good element variable name. Then, in the connector configuration, use the element variable for the url parameter, i.e. the script would become ${url}.

Note that you set a variable of type java.util.ArrayList. This class has no method #elements, so you got the exception you posted.#elements is a method of the class SpinJsonNode, which is a wrapper for native JSON variables, i.e. where you don’t have a direct Java object representation of the value.

Cheers,
Thorben