cancel
Showing results for 
Search instead for 
Did you mean: 

Timer based on variables

ruedesilva
Champ in-the-making
Champ in-the-making
Hi,

I have attached my WF in CallSubscriber.png. Basically I need to have a boundary event/timer on a user task based on a variable. Currently I do not see way to do this. So I had to duplicate the user task and then put an exclusive gateway in front of it so that I take the path with user task with timer or user task without timer, depending on the variable useTimer. This gets very complex and the whole diagram gets complicated as I will start to have duplicated paths. If I can have just a single path where the boundary event/timer is always present but the timer will only start based on a certain variable value.

Is there some way to accomplish this instead of the way I am doing with duplicated tasks/paths?

thanks,
Rue
10 REPLIES 10

jbarrez
Star Contributor
Star Contributor
Why are you duplicating the whole paths? If I understand the diagram, you can simply duplicate the task (one with and one without timer), with a excl. gateway, and keep all the rest unduplicated?

ruedesilva
Champ in-the-making
Champ in-the-making
I cannot just duplicate the task only. If I do that then any subsequent tasks/nodes after that (such as Wait For Next Call) that leads back to the original task (Call Subscriber with timer or Call Subscriber Without Timer) would have two transitions (unless I put another exclusive gateway there). If I do start putting exclusive gateways all over (that needs to transition back to the original node) the diagram could become equally as complex (I am talking in general and not my diagram as that was just a simple  example, but one with many different tasks)

However if there was a way just to turn on/off (or use/not use) a timer on a node/task that would be much easier and elegant?

thanks,
Rue

mhw
Champ in-the-making
Champ in-the-making
Hi,

you can put a serviceTask with a "behavior" just before your two "Call subscriber with timer node"s and define two different transitions. The script task can handle the transition:

<serviceTask id="javaService"
  name="Java service invocation"
  activiti:class="com.bigfirm.decisions.UseTimerCallSubscriber">           
</serviceTask>

The class could be look like this:
public class UseTimerCallSubscriber implements ActivityBehavior {

  public void execute(ActivityExecution execution) throws Exception {
    boolean useTimer = (Boolean) execution.getVariable("useTimer");

    PvmTransition transition = null;
    if(useTimer){
      transition = execution.getActivity().findOutgoingTransition("useTimerTransition");
    } else {
      transition = execution.getActivity().findOutgoingTransition("dontUseTimerTransition");
    }
    execution.take(transition);
  }
 
}

Best regards,

Michael

ruedesilva
Champ in-the-making
Champ in-the-making
Thanks for the reply  but I don't understand. That just seems to get rid of the Exclusive gateway. You would still have two nodes CallSubWithTimer and CallSubWithoutTimer. The issue here is not the Exclusive Gateway, but to minimize duplicate tasks/nodes and paths.

thanks,
Rue

mhw
Champ in-the-making
Champ in-the-making
Thanks for the reply  but I don't understand. That just seems to get rid of the Exclusive gateway. You would still have two nodes CallSubWithTimer and CallSubWithoutTimer. The issue here is not the Exclusive Gateway, but to minimize duplicate tasks/nodes and paths.

thanks,
Rue
Hi Rue,

yes, you would still have two nodes. But you dont have two different paths any more. You can just make a join gateway after the two nodes and all returning transitions direct to the service node before the callsub nodes.

If you want, post your xml definition and I change it accordingly.

regards,
Michael

ruedesilva
Champ in-the-making
Champ in-the-making
Hi Michael,

I have uploaded my latest diagram after some changes. Now it is much simplified to avoid confusion. What I would like to have is one node with timer and someway to turn on/of that timer based on 'useCallSubTimer' variable. Your ServiceTask does pretty much the same thing as the Exclusive Gateway (So I would prefer to have an Exlc Gateway rather than a Service Task that does the samething)

thanks,
Rue

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
🙂 he asked for the XML !!! not the image

mhw
Champ in-the-making
Champ in-the-making
Hi Rue,

your process is now almost what I suggested. You are right, with gateways its more like modeling not programming. So now you do not have duplicated paths.

I do not think that it is possible to turn the timer on/off based on a variable without extending activity.

A first thought (of a newbie) is to extend the class "TimerDeclarationImpl" and overwrite the method "prepareTimerEntity".

I would change the lines:
    TimerEntity timer = new TimerEntity(this);
    timer.setDuedate(duedate);
to

if(executionEntity.getParentVariableScope().getVariable("useCallSubTimer")){
    timer.setDuedate(duedate);
} else {
    timer.setDuedate(new Date()); // do not use timer value
}

But this approach would hard-code the variable name. Just a thought. Other ideas?

regards,
Michael

ruedesilva
Champ in-the-making
Champ in-the-making
I have no ideas. For the Activiti team:  can this be extended/enhanced in the future so that timers can be turned on/off depending on a logical expression or variable?

thanks,
Rue