Search code examples
javaactivitibpmn

activiti:skipExpression doesn't work


Today it took me some time to find out how to use the skipExpression feature of Activiti. I wished I had found a question like this, that's why I'll put it here and answer it myself.

I tried using an activiti:skipExpression in a UserTask like this:

<userTask id="usertask1" name="Order Book" activiti:assignee="myTestUser1" 
  activiti:skipExpression="${skip == 1}">
</userTask>

According to https://activiti.atlassian.net/browse/ACT-2176, this is supposed to be possible since 5.18. But I can't make it work.

I expect that task to be skipped and the following task to be created, but the flow behaves as if the skip expression weren't there (task 1 is created, task 2 isn't created).


Solution

  • From searching Activiti's source code resp. its tests, I found that I have to add an extra variable to each process instance that wants to make use of the skip feature:

        Map<String, Object> params = new HashMap<String, Object>();
        params.put("_ACTIVITI_SKIP_EXPRESSION_ENABLED", true);
        params.put("skip", 1);
    

    Additionally, the tests writes the expression in the process XML's userTask like this:

    activiti:skipExpression="${execution.getVariable('skip') == 1}"
    

    That param is undocumented in the Activiti User Guide of version 5.19 (I'm using 6.0.0.beta1), and there is no word about it in the ticket either, that I mentioned in the question.