Avatar

Correct answer by
Community Advisor

Hello @ClaraBalaguer,

You can achieve the same results with different approaches, one that came to my mind immediately is to set up your workflow in following way:

 

Marcel_Szimonisz_3-1644233373354.png

 

Where following use cases may happen:

  • the email gets rejected and the stop activity will also stop all tasks in progress. So no scheduler is fired.

          Marcel_Szimonisz_7-1644233714083.png

 

  • the email is nor approved either declined and  will be triggered by scheduler. Approval task will be stopped by the End activity with option stop all tasks in progress enabled
  • when the email gets approved the email runs immediately. In case of approved and scheduler trigger is fired one after another, only one will pass to the delivery so you do not send same email twice. That will be set up in Advanced JavaScript activity 

Advanced JS activity will have logic to trigger only once by setting flag that will be saved under instance.vars.triggered. Instance vars because they are visible to entire workflow once set. I would set it in start activity:

Marcel_Szimonisz_5-1644233478651.png

 

In the advanced JS add the following, to the tab "next calls" (two can happen)

 

if (instance.vars.triggered == true){
  task.postEvent(task.transitionByName("alreadyTriggered"));
}else{
  instance.vars.triggered = true;
  task.postEvent(task.transitionByName("ok"));
}
return 0

Where basically with simple condition we set this flag to true when we first run over this JS. Next time the AJS will trigger transition called alreadyTriggered and will finish the workflow. (not the end with stop all tasks.. as the delivery might be processing)

 

Marcel_Szimonisz_6-1644233581396.png

Also do not forget to add new transition called alreadyTriggered

 

Also make sure only decline and delivery done goes to Stop - stop all tasks in progress

 

Marcel

View solution in original post