Case Stage/Task Repetition

Hi,
I’m trying to achieve dynamic activation and repetition on case stages. My scenario is like,

  • I have 3 stages configured s1, s2 and s3.
  • Each stage has an entry sentry that has the condition like ${var:eq(“currentStage”, “s1/s2/s3”)}.
  • In each stage there is a task that defines the next stage to be activated(sets the currentStage variable value).
  • Since the repetition is done each time the sentry is evaluated to true. Say initially currentStage value is ‘s1’. This will be true until the task inside that stage evaluates. So, infinite stages are getting created as condition is always true.

How to tackle this? How can we configure so repetition is evaluated after stage completes?
**In my case there is no possibility to use associations which would solve the issue, by connecting the stages.

1 Like

Hi,

Please note that I don’t pretend to be a Flowable expert, so it would be great to hear about what specialists in the forum have to say (and let me know if my approach is not the way to go). I am facing several use cases related to repetitions and stages, so I tried to implement a solution to your problem.

Looks like it is working.

First step, I created the case model as you describe. I have 3 stages, and an Sentry with no onPart and only an ifPart:

Second step, I use the following expression in each of the 3 stage Sentries (the expression is different for every Sentry, with respectively ‘S1’, ‘S2’ and ‘S3’):

${var:eq("nextStage", "S1")}

Third step, I created a form, which I use in the “start”, “Do 1”, “Do 2” and “Do 3” tasks. The form is used to set the value of the nextStage variable.

When I tried that, the issue was that the engine would go into an infinite loop. So what I did was to add lifecycle listeners in each of the stages. You have to keep in mind that the state transition is different for the first iteration (from “available” to “active”) and for the others (from “wait_repetition” to “active”). I the the following expression in my lifecycle listeners:

${caseInstance.setVariable("nextStage", "not decided")}

With that, I am able to dynamically move from stage to stage, selecting the next stage in the form. Again, I am not an expert so there might well be a better solution (I find it a bit cumbersome to write).

1 Like

By the way, this a part of the documentation that got me to understand quite a few things about the engine: CMMN 1.1 · Flowable Open Source Documentation.

In particular the paragraph entitled “Repetition Rule: Max instance count attribute”.

1 Like

Hi @wasadigi,
Thanks for such a detailed explanation!!!
I faced the same issue(infinite repetition) and i followed the same approach as you did. And i felt the same(bit cumbersome to write).
I have a design that makes this approach of setting the variable to invalid values quite difficult/clumsy.
But i feel like repetition should only be done after completion. That kind of makes more sense i guess.

Please let me know i find a better solution.
Thanks.

Any efficient approaches that someone can suggest?

Thanks…

Hi @wasadigi,
This solution fails for a planitem that is declared as asynchronous. Do you have any alternative?

Thanks…

The CMMN spec is quite clear here on when the sentry needs to be evaluated, so this not something we can change.

Can you elaborate or share your CMMN model. Being async or not shouldn’t have impact on this.