Workflow - Global
-
- UpdatedJan 30, 2025
- 7 minutes to read
- Yokohama
- API reference
The Workflow script include provides methods that interface with the Workflow engine.
Use these methods to manipulate workflows.
Workflow - broadcastEvent(String contextId, String eventName)
Sends the specified event (message) into the workflow context to pass along to the executing activities.
Typical use of this method is to enable activities that wait for some action to occur before proceeding. For additional information on using broadcastEvent, refer to Workflow event-specific functions.
For a list of the available OOB events, refer to Workflow events in the base system.
Name | Type | Description |
---|---|---|
contextId | String | The context ID. |
eventName | String | The name of the event. |
Type | Description |
---|---|
void |
Example
Workflow - cancel(GlideRecord record)
Cancels all running workflows on this record by broadcasting the cancel event to activities in all running workflows on this record.
Name | Type | Description |
---|---|---|
record | GlideRecord | GlideRecord on any table. All workflows running on this record will be cancelled. |
Type | Description |
---|---|
void |
Example
Workflow - cancelContext(GlideRecord context)
Cancels this running context by broadcasting a cancel event to activities in this workflow context.
Name | Type | Description |
---|---|---|
context | GlideRecord | GlideRecord of the running context to cancel. |
Type | Description |
---|---|
void |
Example
Workflow - deleteWorkflow(GlideRecord current)
Deletes all the workflows on the record.
Name | Type | Description |
---|---|---|
current | GlideRecord | GlideRecord for which the caller wants to delete all workflows. This can be any record on any table. |
Type | Description |
---|---|
void |
Example
Workflow - fireEvent(GlideRecord eventRecord, String eventName, Object eventParms)
Fires the named event of a running workflow on the input record.
Used in Activities Approval Coordinator, Timer, Lock, and some others.
Name | Type | Description |
---|---|---|
eventRecord | GlideRecord | Event record listed in the Workflow Executing Activites [wf_executing] table. |
eventName | String | The name of the event to send to the executing workflow. |
eventParms | Object | Optional. Parameters in JSON format used by the event. |
Type | Description |
---|---|
void |
Example
Workflow - fireEventById(String eventRecordId, String eventName)
Fires the named event on the record specified by record ID.
Used in Activities Approval Coordinator, Timer, Lock, and some others.
Name | Type | Description |
---|---|---|
eventRecordId | String | The sys_id of the glide record. |
eventName | String | The name of the event to send to the executing workflow. |
Type | Description |
---|---|
void |
Example
Workflow - getContexts(GlideRecord record)
Returns all workflow contexts for a specified record.
Name | Type | Description |
---|---|---|
record | GlideRecord | GlideRecord for which the caller wants a list of all workflow contexts. This can be any record on any table for which the caller wants the running workflow contexts. |
Type | Description |
---|---|
GlideRecord | GlideRecord in the Workflow context [wf_context] table filtered for all workflow contexts for the specified record (in any state, such as running, cancelled, finished). |
Example
Workflow - getEstimatedDeliveryTime(String workflowId)
Gets the estimated time for a workflow to complete.
Name | Type | Description |
---|---|---|
workflowId | String | Sys_id of the workflow (table wf_workflow) to get the estimated run time. |
Type | Description |
---|---|
String | Display value from a GlideDuration (e.g., 3 days), or blank if unknown. |
Example
2 Days
Workflow - getEstimatedDeliveryTimeFromWFVersion(GlideRecord wfVersion)
Get the estimated elapsed execution time for the workflow version.
Name | Type | Description |
---|---|---|
wfVersion | GlideRecord | GlideRecord on table wf_workflow_version of a specific workflow version for which the caller wants the estimated during of executing. |
Type | Description |
---|---|
String | Display value from a GlideDuration (e.g., 3 days), or blank if unknown. |
Example
Workflow - getReturnValue(String workflowID, Number amount, Boolean result)
Gets the appropriate workflow return value for the input workflow ID. This is either the workflow checked out by the current user or the published workflow with the most recent date.
This is either the workflow checked out by the current user or the published workflow with the most recent date. This method is available starting with the Fuji release.
Name | Type | Description |
---|---|---|
workflowID | String | The sys_id of the workflow (table wf_workflow) |
amount | Number | amount |
result | Boolean | True, if true |
Type | Description |
---|---|
??? | The return value of the workflow as specified by the Return Value activity. Workflows without a Return Value activity return a null value. |
Example
Workflow - getRunningFlows(GlideRecord record)
Gets all the currently running workflow contexts for the input record.
The input record is any record on any table for which the caller wants the running workflow contexts.
Name | Type | Description |
---|---|---|
record | GlideRecord | GlideRecord of the record for which the caller wants a list of all running workflows. |
Type | Description |
---|---|
GlideRecord | GlideRecord on table wf_context and filtered for all executing workflow contexts. |
Example
Workflow - getVersion(String workflowID)
Gets the appropriate workflow version for the input workflow ID. This is either the workflow checked out by the current user or the published workflow with the most recent date.
This is either the workflow checked out by the current user or the published workflow with the most recent date.
Name | Type | Description |
---|---|---|
workflowID | String | The sys_id of the workflow (table wf_workflow) |
Type | Description |
---|---|
none |
Example
Workflow - getVersionFromName(String workflowName)
Returns the appropriate workflow version for the input workflow name.
See getVersion() for more information.
Name | Type | Description |
---|---|---|
workflowName | String | Name of the workflow (table wf_workflow) |
Type | Description |
---|---|
void |
Example
Workflow - getWorkflowFromName(String workflowName)
Returns the sys_id of the workflow associated with the specified workflow name.
Name | Type | Description |
---|---|---|
workflowName | String | Name of the workflow. |
Type | Description |
---|---|
String | The sys_id of the workflow associated with the passed in name. |
Example
Workflow - hasWorkflow(GlideRecord record)
Determines if a specified record has any workflow contexts associated to it.
This includes running and completed workflow contexts.
Name | Type | Description |
---|---|---|
record | GlideRecord | GlideRecord under scrutiny. This GlideRecord can be from any table. |
Type | Description |
---|---|
Boolean | True, if record has associated workflow; otherwise, returns False. |
Example
false
Workflow - restartWorkflow(GlideRecord current, Boolean maintainStateFlag)
Recalculates the approvals and tasks for a workflow by adding new approvals and tasks, while not resetting current approvals and tasks.
You can use this method to perform such tasks as adding a company to a change request, without resetting the current approvals for companies already in the workflow.
Name | Type | Description |
---|---|---|
current | GlideRecord | GlideRecord of the record this workflow is executing. This can by any record on any table. |
maintainStateFlag | Boolean | Flag that indicates whether to maintain all approvals and tasks in their
current state. Valid values:
|
Type | Description |
---|---|
void |
Example
This example shows the workflow being restarted with the approval file changing from Rejected to Requested.
Workflow - runFlows(GlideRecord record, String operation)
Runs all workflows for a given record in a given table and its descendant tables.
Sample usage can be seen in the Script Includes "SNC - Run parent workflows", and "SNC - Run parent workflows (Approval)".
Name | Type | Description |
---|---|---|
record | GlideRecord | GlideRecord to run workflows against. |
operation | String | Database operation. Valid values:
|
Type | Description |
---|---|
void |
Example
Workflow - startFlow(String workflowId, GlideRecord current, String operation, Array vars)
Starts a specified workflow.
See script include WorkflowScheduler and Business Rule "Start Workflow" on table sc_req_item for examples of use.
Example
Workflow - startFlowFromContextInsert(GlideRecord context, String operation)
Helper method for business rule Auto start on context.
Name | Type | Description |
---|---|---|
context | GlideRecord | GlideRecord on table wf_context of a new record (the "current" record in the business rule). |
operation | String | Database operation being performed. One of insert, update, delete. |
Type | Description |
---|---|
void |
Example
Workflow - startFlowRetroactive(String workflowId, Number retroactiveMSecs, GlideRecord current, String operation, Array, ???)
Used by business rule Start Workflow on table task_sla. This starts a workflow and the extra arguments to this method are used by activity "Timer" to pause the execution of the workflow for some duration.
Type | Description |
---|---|
GlideRecord | A GlideRecord on table wf_context on the inserted record for this newly created workflow context. |
Example
Workflow - Workflow()
Constructor for Workflow class.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
void |
Example
On this page
- Workflow - broadcastEvent(String contextId, String eventName)
- Workflow - cancel(GlideRecord record)
- Workflow - cancelContext(GlideRecord context)
- Workflow - deleteWorkflow(GlideRecord current)
- Workflow - fireEvent(GlideRecord eventRecord, String eventName, Object eventParms)
- Workflow - fireEventById(String eventRecordId, String eventName)
- Workflow - getContexts(GlideRecord record)
- Workflow - getEstimatedDeliveryTime(String workflowId)
- Workflow - getEstimatedDeliveryTimeFromWFVersion(GlideRecord wfVersion)
- Workflow - getReturnValue(String workflowID, Number amount, Boolean result)
- Workflow - getRunningFlows(GlideRecord record)
- Workflow - getVersion(String workflowID)
- Workflow - getVersionFromName(String workflowName)
- Workflow - getWorkflowFromName(String workflowName)
- Workflow - hasWorkflow(GlideRecord record)
- Workflow - restartWorkflow(GlideRecord current, Boolean maintainStateFlag)
- Workflow - runFlows(GlideRecord record, String operation)
- Workflow - startFlow(String workflowId, GlideRecord current, String operation, Array
vars)
- Workflow - startFlowFromContextInsert(GlideRecord context, String operation)
- Workflow - startFlowRetroactive(String workflowId, Number retroactiveMSecs, GlideRecord
current, String operation, Array, ???)
- Workflow - Workflow()