Generate workflow activity
Summarize
Summary of Generate workflow activity
The Generate workflow activity in ServiceNow immediately creates task or approval records for any subsequent task or approval activities in the workflow path. These pre-generated tasks and approvals become active only when their respective activities are reached during workflow execution. This enables workflows to have a predefined set of sequential tasks or approvals that must still be completed in order. The Generate activity is available only for workflows running on tables that extend the Task table.
Show less
Key Features
- Pre-generation of tasks and approvals: Tasks are created with state Pending, and approvals with state Not Requested, along with calculated expected start and due dates.
- Sequential completion: Even though tasks and approvals are pre-generated, they must be completed sequentially as defined in the workflow.
- Duration-based scheduling: Expected start and due dates are calculated based on the expected durations of all tasks and approvals between the Generate activity and the specific activity, using the longest duration in branched paths.
- Multiple usage: The Generate activity can be used multiple times to refresh tasks and approvals, which is helpful if approvers or related information change during workflow execution.
- Excluding activities: Activities can be excluded from generation by selecting the Skip during generate checkbox on conditions, commonly used for rejected approvals and certain activity conditions.
- Input variables: Options to specify whether to generate tasks and/or approvals or just use them to compute durations without actual creation.
Practical Use and Behavior
When the Generate activity runs, it follows all transitions to subsequent task or approval activities, creating the corresponding records with appropriate states and scheduling. Tasks run as the user who completes the preceding task, and approvals run as the user whose actions match the approval conditions. This process ensures accurate scheduling and seamless workflow progression.
For branched workflow paths, the scheduling calculation uses the longest path duration to determine start and due dates for tasks following the branch, ensuring proper sequence and timing.
Example Scenario
In a workflow example, approvals Approval-2 and Approval-3 are generated, while Approval-4 is skipped due to the Skip during generate setting on the Rejected condition of Approval-3.
Another example shows task scheduling based on expected durations. For instance, if the Generate activity runs on January 1, Task 1 (1 day) starts January 1 and ends January 2, Task 2 starts January 2, and so forth. The scheduling reflects the longest path in the workflow to ensure tasks start and finish in proper order, such as Task 5 starting on January 4, aligned with the longest preceding path.
The Generate activity immediately creates task or approval records from any task or approval activities placed after the Generate activity in the workflow path. These pre-generated tasks and approvals start when the task and approval activities are reached during flow execution. This allows a task to have a set of associated pre-generated sequential tasks or approvals, but still require them to be completed in order.
By default, the workflow does not create any tasks or approvals until it reaches them in the workflow.
- If it is a task activity,
creates the task and sets:
- The State to Pending
- The Expected Start Date
- The Due Date
Note:Task activities run as the user whose actions complete the task the workflow was waiting for and advances the workflow. - If it is an approval activity, creates the approvals and sets:
- The approval State to Not Requested
- The Expected Start Date
- The Due Date
Note:Approval activities run as the user whose actions match the approve or reject conditions the workflow was waiting for and advances the workflow.
Expected start dates and due dates are calculated based on the Expected Duration of all of the tasks and approvals between the Generate activity and the activity being updated. In the case of a branched path (between a Branch and Join activity), the longer duration will be used for any post-branch activities.
The Generate activity can be used more than once, and any tasks or approvals will be refreshed with updated information. This is useful in situations where the list of approvers or other important information is still editable while the workflow is in process and it may be necessary to update or correct the generated approvals or tasks.
- Rejected (for any of the approval activities)
- No condition of If activity
- Continue condition of Turnstile activity
- Incomplete condition of Join activity
Input variables
Input variables determine the initial behavior of the activity.
| Field | Description |
|---|---|
| Generate approvals | If selected, approvals are created when running the Generate activity. If cleared, the approvals are used to compute their estimated duration, but no approvals are created. |
| Generate tasks | If selected, tasks are created when running the Generate activity. If cleared, the tasks are used to compute their estimated duration, but no tasks are created. |
States
| State | Description |
|---|---|
| Executing | The activity is executing. |
| Finished | The activity finished running. See the result value for the outcome of the activity. |
| Cancelled | This activity, or the workflow that contains this activity, was canceled. |
Example
- Approval-2
- Approval-3
Approval-4 is skipped since the Rejected condition of Approval-3 has Skip during generate selected.
| Task | Expected Start Date | Reason | Due Date |
|---|---|---|---|
| Task 1 (1 day) | Jan. 1, 2016 | Jan. 2, 2016 | |
| Task 2 (1 day) | Jan. 2, 2016 | Task 1 is 1 day | Jan. 3, 2016 |
| Task 3 (2 days) | Jan. 1, 2016 | Jan. 3, 2016 | |
| Task 4 (1 day) | Jan. 3, 2016 | Task 3 is 2 days | Jan. 4, 2016 |
| Task 5 (1 day) | Jan. 4, 2016 | Task 4 ends the latest before the Join | Jan. 5, 2016 |
Notice that Task 5 starts on Jan. 4, 2016 since the longest path (based on due dates) to the Join is Task 3/Task 4.