Hello,
I am trying to figure out how to check for an empty array while doing a conditional check. Here is the structure of the JSON object in Camunda Cockpit.
{“artifacts”: [{“id”: “1”,“status”: “not_started”},{“id”: “2”,“status”: “not_started”},{“id”: “3”,“status”: “not_started”}]}
As I go through each of the items, I am getting a hold of each item (Javascript Script Task):
var artifacts = execution.getVariable(“artifacts”);
var currentItem = artifacts.elements().get(0);
execution.setVariable(“currentItem”, currentItem);
Then, in a separate step, I remove the currentItem from the “artifacts” object doing this:
var artifacts = execution.getVariable(“artifacts”);
var item = execution.getVariable(“currentItem”);
artifacts.remove(item);
execution.setVariable(“artifacts”, artifacts);
In the end, the “artifacts” object looks like this: []
However, when I am trying to check the length of the “artifacts” object array in a sequence flow expression, I always get an error.
"org.camunda.bpm.engine.ProcessEngineException: Unknown property used in expression: ${S(artifacts).length > 0}. Cause: Could not find property length in class
org.camunda.spin.impl.json.jackson.JacksonJsonNode"
Here are some of the things I have tried:
${artifacts.length > 0}
${artifacts.elements().length > 0}
${S(artifacts).length > 0}
Thanks.