Hi guys,
Ive used multi-instance loops over java collections, however is it possible to configure a multi-instance task over a single process variable which is effectively a JSON array?
regards
Rob
Hi guys,
Ive used multi-instance loops over java collections, however is it possible to configure a multi-instance task over a single process variable which is effectively a JSON array?
regards
Rob
Hi Rob,
I haven’t tried this myself yet. Assuming the JSON array variable is a Spin JSON value, it should be possible to write camunda:collection="${variable.elements()}"
in the multi-instance configuration.
Cheers,
Thorben
Thanks Thorben,
worked like a charm!
regards
Rob
Hi @Webcyberrob,
Could you please give more details how you pass a JSON array in the multi-instance collection?
I have a process variable “order” like the following:
[{“orderID”:1,“orderNo”:“6RETYY”,“orderQty”:2},
{“orderID”:2,“orderNo”:“45RFFS”,“orderQty”:5},
{“orderID”:3,“orderNo”:“34HJYT”,“orderQty”:3}]
(actually I have a list of objects retrieved by the database which I then serialize into a process variable:
ObjectValue ordersDataValue = Variables.objectValue(orderEntities)
.serializationDataFormat(Variables.SerializationDataFormats.JSON)
.create();
execution.setVariable("orders",ordersDataValue);
I would like my cardinality to be the size of the array.
What should I write in the collection of the multi-instance task? And what in the “Element Variable”?
And then, in each of the multi-instance, how do I access any property, e.g. OrderQty?
Thanks!
Hi @StephenOTT,
I had already seen that post but there you set the “collection” variable as
var collection = S('{ "collection" : ["System 1", "System 3"] }');
while I I have set it as:
[{“orderID”:1,“orderNo”:“6RETYY”,“orderQty”:2}, {“orderID”:2,“orderNo”:“45RFFS”,“orderQty”:5}, {“orderID”:3,“orderNo”:“34HJYT”,“orderQty”:3}]
Also, you append the values after the DMN task but how can I append the values?
Thanks!
@kontrag you need to convert your json array into a Java collection. Hence the use of SPIN + the .elements()
function.
Any easy way to make the conversion?
Also, I don’t have a multi-instance task like your DMN before my actual multi-instance task.
Why do I need the end listener to update the variable?
Can’t I get it the “combinedResult” variable with the values right after the generation of the collection?
@kontrag use the SPIN library in your java delegate to generate a spin object and then do a .elements()
Sorry, this was mistake on my part; i was thinking of another thread.
Hi again,
I have the following string:
String orders = [{“orderID”:1,“orderNo”:“6RETYY”,“orderQty”:2}, {“orderID”:3,“orderNo”:“34HJYT”,“orderQty”:3}]
How do I convert it into JSON?
I try:
JsonValue orders = SpinValues.jsonValue(orders).create();
execution.setVariable("orders", orders);`
but I get an error:
Cannot find serializer for value 'Value 'null' of type 'json''.
Thanks!
@kontrag see the spin docs on reading Json string into spin: https://docs.camunda.org/manual/7.7/reference/spin/json/01-reading-json/#reading-json-from-a-string
Thanks @StephenOTT!
I simply wrote
String orders_str = [{“orderID”:1,“orderNo”:“6RETYY”,“orderQty”:2}, {“orderID”:3,“orderNo”:“34HJYT”,“orderQty”:3}]
SpinJsonNode orders = S(orders_str, json());
and worked
@kontrag, Can you please tell me how you have configured the multiinstance in your bpmn. I am also trying to implement something like this. Also how do you access each object in the json and use them in the bpmn user task? Any help is much appreciated.