cancel
Showing results for 
Search instead for 
Did you mean: 

Starting a timer only if bpm:dueDate is set

bedag-moo
Champ in-the-making
Champ in-the-making
I am working on a workflow where bpm:dueDate is not mandatory, but if one is set the initiator should be notified if it is missed. I have successfully attached a timer to the task:

         <timer duedate="#{bwf_editDueDate}">
            <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
               <script>
                  var mail = actions.create("mail");
                  mail.parameters.to = initiator.properties["cm:email"];
                  mail.parameters.subject = "Zeitüberschreitung: " + bpm_workflowDescription;
                  mail.parameters.from = "Alfresco";
                  mail.parameters.text = person.properties.firstName + " " + person.properties.lastName +
                     " hat den Auftrag " + bpm_workflowDescription + " nicht rechtzeitig erledigt.";
                  mail.execute(bpm_package);
               </script>
            </action>
         </timer>

However, this throws an exception if bpm:dueDate is null. Is there a way to set a timer only if bpm:dueDate is set?
2 REPLIES 2

birgir
Champ in-the-making
Champ in-the-making
Use a decision node to check if the variable is set. You could do something like this, assuming bwf_editDuedate is an object.


<decision name="DueDateDecision">
      <transition name="tr2" to="Complete"></transition>
      <transition name="" to="SetTimer">
         <condition>#{bwf_editDuedate != null}</condition>
      </transition>
   </decision>


You could have a look at Jeff Potts code for an example. http://www.ecmarchitect.com/alfresco-developer-series/

bedag-moo
Champ in-the-making
Champ in-the-making
I don't want to duplicate the task since there is a fair amount of customization present (several event scripts, custom task model, localization of the task model, …), but the lifetime of the timer should be limited by the task. I know only one way to accomplish the latter; a <timer> sub-element to <task> (I didn't get <create-timer> to work, I suspect due to a bug.)

For now, I always create the timer, but set its due date to January 1st, 3000 if no due date is specified. I doubt my script will still be used then 😉

      <task name="bwf:edit" swimlane="editor">
         <event type="task-create">
            <script>
               if (bwf_editDueDate != void) taskInstance.dueDate = bwf_editDueDate;
               taskInstance.priority = bpm_workflowPriority;
            </script>
         </event>
         <timer duedate="#{bwf_editDueDate == null ? never : bwf_editDueDate}">
            <action ref-name="sleepyheadAlert"/>
         </timer>
      </task>

where never is initialized by
         <script>
            <variable name="never" access="write"/>
            <expression>
               never = new Date(3000,0,1);
            </expression>
         </script>
(I didn't inline the variable since jBPM EL does not support the new operator as far as I know).

Now I just have to get the action reference to work (no, I do not want to duplicate its code in every task, the code is already cluttered enough).