Call external service in a loop based on array length?

Hello,

I’m wanting to accept input from a form that contains a dynamic sized JSON Object containing a key with an array of items that I want to execute an external service on:

{
"name":"John",
"age":30,
"cars":[ "Ford", "BMW", "Fiat" ]
}

I would want to call the external service with a payload containing the name/age/cars, in this case 3 times, sending only 1 car at a time until the array was exhausted, but this array is dynamic sized so the next form input could have 10 cars.

So I suspect I would need JS to loop across the object and register variables containing each payload first? and then through multiple instances, or loop with exclusive gateway, or something of the like, actually loop over the service task. I’m very new to Camunda, but ok with JS, but having a hard time envisioning how to put this down in modeler. If you could point me to an example BPMN file doing similar that would be helpful, appreciate your time and support with helping me learn this new tool.

1 Like

see:

You can use the same features but on a service task or a script task which is calling your external service.

You use the multi-instance and configure the collection of the multi-instance to be the array in your json object.

some javascript:

S(JSON.stringify(myJsonObject)).prop('cars').elements()

See the links in the DMN looping thread for more details.

1 Like