cancel
Showing results for 
Search instead for 
Did you mean: 

How to start task in date

gslamy
Champ in-the-making
Champ in-the-making
Hello everybody!

I have some problem with start my task in date from "bpm_workflowDueDate" field.

I extracted date (if it works..):

    <startEvent id="startevent" name="Start" activiti:initiator="initiator" activiti:formKey="scwf:startstaff"> 
      <extensionElements>
        <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string>      
               <![CDATA[execution.setVariable('startdate', task.getVariableLocal('bpm_workflowDueDate'));]]>
            </activiti:string>
          </activiti:field>
        </activiti:taskListener>
      </extensionElements>
    </startEvent>

Now I need start next task in date from variable ("startdate"-3 days). I tried to add a timer, but I think it has a different date format and doesn't work.

Please, help me with this question, I can't find solution. Thank you.
6 REPLIES 6

darkredd
Star Contributor
Star Contributor
Hi,

Activiti timers use date formats in the ISO standard. You can use the Alfresco Utility method to convert the date you construct to the required format. http://docs.alfresco.com/4.1/references/API-JS-Utility-fromISO8601.html

gslamy
Champ in-the-making
Champ in-the-making
I am newbie. I don't understand how to use this code it in my workflow.bpmn. I have to paste it in <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener"> ?
If I got the date in variable "startdate", then how to use it in this code? Do I need only the number of days to use them between the tags <timeDate></timeDate>. Maybe there are other ways?

var date = new Date();
var timeInMillisecs = date.getTime();
var ISODate = utils.toISO8601(timeInMillisecs);
var origDate = utils.fromISO8601(ISODate);

Could you give an example of the code within a workflow file?
Thank you in advance for your help!

darkredd
Star Contributor
Star Contributor
Hi,

I do not particularly have a workflow with what you are expecting, but I have a workflow that uses a timer like this:

    <boundaryEvent id="reminderTimer" name="Reminder Timer" attachedToRef="processingTask" cancelActivity="false">
      <timerEventDefinition>
        <timeDate>${reminderDate}</timeDate>
      </timerEventDefinition>
    </boundaryEvent>

The boundryEvent is attached to a userTask. I do not think you can attach a timer to a start event though.
The date variable I set it in the script as follows:
execution.setVariable('reminderDate', utils.toISO8601(reminderDate));


If you are still not making any headway with this, I suggest you start by learning the basics of creating and deploying workflows.
Here is a like to get you started: http://jmuras.com/blog/2012/creation-of-workflow-in-alfresco-using-activiti-step-by-step/

Firstly, design a simple workflow before you start adding complex logic to your workflow designs; then you can start building up as you get to understand how everything fits together.

gslamy
Champ in-the-making
Champ in-the-making
Could I use variable "startdate" from:

    <startEvent id="startevent" name="Start" activiti:initiator="initiator" activiti:formKey="scwf:startstaff"> 
      <extensionElements>
        <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string>      
               <![CDATA[execution.setVariable('startdate', task.getVariableLocal(utils.toISO8601('bpm_workflowDueDate')));]]>
            </activiti:string>
          </activiti:field>
        </activiti:taskListener>
      </extensionElements>
    </startEvent>

in my timer:

    <intermediateCatchEvent id="timerintermediatecatchevent1" name="TimerCatchEvent">
      <timerEventDefinition>
        <timeDate>${startdate}</timeDate>
      </timerEventDefinition>
    </intermediateCatchEvent>

darkredd
Star Contributor
Star Contributor
Hi,

<blockquote>The boundryEvent is attached to a userTask. I do not think you can attach a timer to a start event though.</blockquote>

You need to understand the way different components of the process definition work first. You cannot attach a timer to a start event since it is a starting task and not a waiting one. A start event only trigger for a very short while to kick start the workflow process. Once a task is dead the attached timer dies too therefore it will not fire.

I strong recommend you <strong>READ</strong> the Activiti user guide here: http://activiti.org/userguide/index.html#bpmnStartEvents

<blockquote>8.2.6. Start Events
A start event indicates where a process starts. The type of start event (process starts on arrival of message, on specific time intervals, etc.), defining how the process is started is shown as a small icon in the visual representation of the event. In the XML representation, the type is given by the declaration of a sub-element.

Start events are always catching: conceptually the event is (at any time) waiting until a certain trigger happens.

In a start event, following Activiti-specific properties can be specified:

initiator: identifies the variable name in which the authenticated user id will be stored when the process is started.<blockquote>
Example: 1
<startEvent id="request" activiti:initiator="initiator" />



gslamy
Champ in-the-making
Champ in-the-making
But I can attach a Timer to SequenceFlow: