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.
- Create a workflow.
- Open the workflow for editing in the workflow editor.
- Add some elements to the workflow schema.
- 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.
- Click the Scriptable task element.
- Enter a name and description for the scripted workflow element in the Details properties tab in the right pane.
- On the Inputs/Outputs properties tab, create a workflow variable.
- Name the variable timerDate.
- Select Date from the list of variable types.
- Leave the variable value text box blank. A scripted function provides this value.
- Click Create.
- Click the Scripting tab for the scripted workflow element.
- Define a function to calculate and generate a Date object named timerDate in the scripting pad in the Scripting tab.
timerDate = new Date(); System.log( "Current date : '" + timerDate + "'" ); timerDate.setTime( timerDate.getTime() + (86400 * 1000) ); System.log( "Timer will expire at '" + timerDate + "'" );
- Click Save and confirm your selection.
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.