Search code examples
camundabpmncamunda-modeler

How to Get Camunda ArrayList Length


I have this variable called ListItems in Camunda 7.16 on Java 14. The variable Type based on the Variables tab is an Object and its value says java.util.ArrayList. I'm stumped as I tried to get the item count in ListItems as a parameter in http-connector payload with Assignment type of String or expression.

{
     "ProcessNo": "${execution.processBusinessKey}",
     "TotalItem": "${S(ListItems).length}"
}

I have tried the following: ${S(ListItems).length}, ${S(ListItems).length()}, ${S(ListItems).size()}, ${(ListItems).size()}, and a the following Script Task (in Inline Javascript)

execution.getVariable("ListItem").size();

I'm running out of idea what to try next.


Solution

  • In the end I had a workaround instead of the variable being an Object or List, I store it as JSON in Camunda and get the length this way:

    S(execution.getVariable("ListItem")).elements().length;
    

    Note:

    • execution.getVariable("ListItem") to parse the ListItem json.

    • .elements() to get all of the items in the JSON list.

    • And finally .length to get its size.

    Storing variable as "native" format be it Object, Map, List is kinda hard to work with in Camunda at times. But they seem to have better size limit (text variables are limited to 4000 characters).