5 Replies Latest reply on Oct 26, 2007 10:46 AM by A V

    How to set the timer duedate dynamicly

    abdelak lib Newbie

      hello,
      I've just started to use JBPM, and I'd like to set the timer duedate dinamicly (using process variable). but it doesn't work;
      here is my process :

      <process-definition
       xmlns="urn:jbpm.org:jpdl-3.1" name="rec_facture">
       <event type="process-start">
       <script>
       executionContext.setVariable("action_delay", "6 seconds");
       </script>
       </event>
       <start-state name="create_reclamation">
       <transition name="to_action1" to="action_"></transition>
       </start-state>
       <end-state name="end1"></end-state>
       <state name="action_">
       <timer name="actionTimer" duedate="#{action_delay}" transition="action_time_out">
       <action name="action_t" class="com.sample.action.ActionTimeOutActionHandler">
       <action_name>action_test</action_name>
       </action>
       </timer>
       <transition name="action_time_out" to="end1"></transition>
       <transition name="new_action" to="action_"></transition>
       </state>
      </process-definition>
      


      when I run my test application I got this message
      ERROR GraphElement : action threw exception: improper format of duration '#{action_delay}'
      

      thanks for help

        • 1. Re: How to set the timer duedate dynamicly
          Ronald van Kuijk Master

          Correct, the timer does not accept EL. File a jira issue if you want this to happen. Not sure if and when it will be implemented.

          • 2. Re: How to set the timer duedate dynamicly
            Koen Aers Master

            By the way, you can always work around the issue by changing the timer due date programmatically in an action.

            Regards,
            Koen

            • 3. Re: How to set the timer duedate dynamicly
              abdelak lib Newbie

              thanks for your answer, I solved the problem by using an action to update the timer due date .
              here is the action

              .....
              public class UpdatingTimerActionHandler implements ActionHandler {
              
               private static final long serialVersionUID = 1L;
              
              
              
               /**
               * update
               */
               public void execute(ExecutionContext context) throws Exception {
              
               System.out
               .println("start timer updating");
               String timerName = "actionTimer";
               String delay = context.getContextInstance().getVariable("action_delay").toString();
               //System.out.println("new delay : "+ delay);
               if (delay!=null && !delay.equals("")){
               try{
               SchedulerSession schedulerSession = context.getJbpmContext().getSchedulerSession();
               Duration duration = new Duration(delay);
               Date newDueDate = new BusinessCalendar().add(new Date(), duration);
               List timers = schedulerSession.findTimersByName(timerName, context.getToken());
               for(Object o : timers) {
               Timer timer = (Timer)o;
               log.info("Timer '" + timer.getName() + "' due date is " + timer.getDueDate());
               try{
               timer.setDueDate(newDueDate);
               }catch(Exception e) {
               throw new Exception("Timer '" + timer.getName() + "' due date was not updated to " +
               newDueDate + "': " + e);
               }
               schedulerSession.saveTimer(timer);
               log.info("Timer '" + timer.getName() + "' due date updated to " + timer.getDueDate());
               }
               }
               catch(Exception ex){
               ex.printStackTrace();
               }
               }
               System.out
               .println("finish timer updating");
               }
               public Log log = LogFactory.getLog(this.getClass());
              
              }
              

              thanks again

              • 4. Re: How to set the timer duedate dynamicly
                David Roberts Apprentice

                Great, thanks for posting your solution. I'm sure it will come in handy...

                • 5. Re: How to set the timer duedate dynamicly
                  A V Newbie

                  Hi,

                  I'm afraid your code will not work with jBPM 3.2, but i'm currently looking for a solution to set the duedate in an ActionHandler with Version 3.2. Does anybody know a way to do that? In the forum I only found solutions for older jBPM Versions and I couldn't get it work by trying out either.

                  Thank you very much for any hints.