UniversalTaskUtils - Scoped, Global
-
- UpdatedJan 30, 2025
- 3 minutes to read
- Yokohama
- API reference
The UniversalTaskUtils script include provides methods for managing universal tasks.
With the ServiceNow Universal Task application, agents can create tasks for employees. For example, agents can ask for additional information or request an action to resolve a parent ticket or request. Universal tasks are available for any ticket type that extends the Task [task] table.
Using this script include you can change the state of active universal tasks to "Complete" or "Cancelled", obtain all active universal tasks for a specified parent task, check whether a parent universal task has any children, and apply templates to a universal task record. You can use these methods in scripts and in the Visable condition builders on the Tab configuration form to manage the data that appears on the Universal Task tab. For additional information, see Add a Task tab on the Standard Ticket page.
You can use this script include in both scoped and global applications. The Universal Task application (sn_uni_task) must be installed on the associated instance to have access to this script include. You must always specify the
sn_uni_task
namespace when calling methods in this API.
For additional information on the Universal Task application, see Universal Task.
UniversalTaskUtils - applyTemplate(String templateSysId, GlideRecord uniTaskGr)
Applies the specified universal task template to the specified universal task record.
Before you can use this method, there must be universal task templates configured in your instance. For details, see Universal Task templates.
Name | Type | Description |
---|---|---|
templateSysId | String | Sys_id of universal task template to apply to the specified universal task record. Table: Universal Task Template [sn_uni_task_template] |
uniTaskGr | GlideRecord | GlideRecord of the universal task record to which to apply the template. |
Type | Description |
---|---|
None | Any errors are written to the system log. |
Example
This code example shows a function that acquires, and then applies, the Feedback Template.
UniversalTaskUtils - getActiveChildTasks(String parentSysId)
Returns the active child task records, in the form of a GlideRecord, for the specified parent ticket.
You can then use the GlideRecord API, scoped or global depending on the calling application's scope, to access the returned data, such as using the getRowCount() method to count active tasks.
Name | Type | Description |
---|---|---|
parentSysId | String | Sys_id of the parent ticket whose active child tickets to return. |
Type | Description |
---|---|
GlideRecord | GlideRecord that contains all active child task records for the specified parent task. |
Example
The following example shows a function that obtains all active child tasks for the current sys_id and then uses getRowCount() to obtain the number of active child tasks.
UniversalTaskUtils - hasTasksToShow(GlideRecord current)
Checks whether the specified parent ticket has any universal tasks that are in the work-in progress or complete state.
You can use this method to determine whether to show the Universal Task tab to a requester in a standard ticket configuration only if there are tasks that are work-in progress or complete.
Name | Type | Description |
---|---|---|
current | GlideRecord | GlideRecord of the parent ticket to check. |
Type | Description |
---|---|
sys_id | If universal tasks are associated with the parent ticket, the sys_id of the
parent ticket; otherwise null. Data type: String |
Example
The following example shows a function that calls this method to check for universal tasks.
UniversalTaskUtils - markActiveChildTasksCancelled(String parentSysId)
Changes the state of all active universal tasks under the specified parent ticket to "Cancelled".
Name | Type | Description |
---|---|---|
parentSysId | String | Sys_id of the parent ticket whose active child universal tasks' state should be changed to "Cancelled". |
Type | Description |
---|---|
None |
Example
This code example shows how to use this method to update the states of all universal tasks associated with the specified parent task to cancelled.
UniversalTaskUtils - markActiveChildTasksCompleted(String parentSysId)
Changes the state of all active child universal tasks associated with the specified parent ticket to "Complete".
Name | Type | Description |
---|---|---|
parentSysId | String | Sys_id of the parent ticket whose active child universal tasks' state should be changed to "Complete". |
Type | Description |
---|---|
None |
Example
This code example shows how to use this method to update the states of all universal tasks associated with the specified parent task to completed.
On this page
- UniversalTaskUtils - applyTemplate(String templateSysId, GlideRecord uniTaskGr)
- UniversalTaskUtils - getActiveChildTasks(String parentSysId)
- UniversalTaskUtils - hasTasksToShow(GlideRecord current)
- UniversalTaskUtils - markActiveChildTasksCancelled(String parentSysId)
- UniversalTaskUtils - markActiveChildTasksCompleted(String parentSysId)