To implement a timer-based long-running workflow, first you set a timer that suspends the workflow until a specific time and date, and then you add a Waiting timer element to a workflow.

Set a Relative Time and Date for Timer-Based Workflows

You can set the timer.date variable of a Waiting timer element to a relative time and date by binding it to a Date object. You define the Date object in a scripted function.

When the time on the given date arrives, the timer-based long-running workflow reactivates and continues its run. For example, you can set the workflow to reactivate at midday on February 12. Alternatively, you can create a workflow element that calculates and generates a relative Date object according to a function that you define. For example, you can create a relative Date object that adds 24 hours to the current time.

Prerequisites

  • Create a workflow.
  • Open the workflow for editing in the workflow editor.
  • Add some elements to the workflow schema.

Procedure

  1. Drag a Scriptable task element from the Generic menu in the left pane to the workflow schema, and place it before the element that requires the relative Date object for its timeout.date variable.
  2. Click the Scriptable task element.
  3. Enter a name and description for the scripted workflow element in the Details properties tab in the right pane.
  4. On the Inputs/Outputs properties tab, create a workflow variable.
    1. Name the variable timerDate.
    2. Select Date from the list of variable types.
    3. Leave the variable value text box blank. A scripted function provides this value.
    4. Click Create.
  5. Click the Scripting tab for the scripted workflow element.
  6. Define a function to calculate and generate a Date object named timerDate in the scripting pad in the Scripting tab.

    For example, you can create a Date object by implementing the following JavaScript function, in which the timeout period is a relative delay in milliseconds.

    timerDate = new Date();
    System.log( "Current date : '" + timerDate + "'" );
    timerDate.setTime( timerDate.getTime() + (86400 * 1000) );
    System.log( "Timer will expire at '" + timerDate + "'" );

    The preceding example JavaScript function defines a Date object that obtains the current date and time by using the getTime method and adds 86,400,000 milliseconds, or 24 hours. The Scriptable task element generates this value as its output parameter.

  7. Click Save and confirm your selection.

Results

You created a function that calculates and generates a Date object. A Waiting timer element can receive this Date object as an input parameter, to suspend a long-running workflow until the date encapsulated in this object. When the workflow arrives at the Waiting timer element, it suspends its run and waits for 24 hours before continuing.

What to do next

You must add a Waiting timer element to a workflow to implement a timer-based long-running workflow.

Create a Timer-Based Long-Running Workflow

If you know that a workflow has to wait for a response from an outside source for a predictable time, you can implement it as a timer-based long-running workflow. A timer-based long-running workflow waits until a given time and date before resuming.

You implement a workflow as a timer-based long-running workflow by using the Waiting timer element.

Prerequisites

  • Create a workflow.
  • Open the workflow for editing in the workflow editor.
  • Add some elements to the workflow schema.

Procedure

  1. Drag a Waiting timer element from the Generic menu in the left pane to the workflow schema, and position it where you want to suspend the workflow run.
    If you implement a scriptable task to calculate the time and date, the scriptable task element must precede the Waiting timer element.
  2. Click the Waiting timer element.
  3. Enter a description of the reason for implementing the timer in the Details properties tab in the right pane.
  4. Click the Inputs tab.
    The timer.date parameter appears in the list of variables.
  5. Bind the timer.date parameter to an appropriate Date object.
    • Select a predefined Date object from the proposed list, for example one defined by a Scriptable task element elsewhere in the workflow.
    • Alternatively, create a Date object that sets a specific date and time for the workflow to await.
  6. (Optional) Create a Date object that sets a specific date and time that the workflow awaits.
    1. Click the Select variable text box, and then click Create New.
      The New Variable dialog box appears.
    2. Enter a name and description for the variable.
    3. Click the Value text box to set the variable value.
      A calendar appears.
    4. Use the calendar to set a date and time at which to restart the workflow.
    5. Click Create.
  7. Click Save and confirm your selection.

Results

You defined a timer that suspends a timer-based long-running workflow until a set time and date.

What to do next

You can create a long-running workflow that waits for a trigger event before continuing.