---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# UniversalTaskUtils - Scoped, Global

# UniversalTaskUtils - Scoped, Global {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 3 minutes to read

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](https://www.servicenow.com/docs/access?context=config-stdtktpage-for-ut&version=xanadu&pubname=xanadu-employee-service-management&ft:locale=en-US).

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](https://www.servicenow.com/docs/access?context=universal-task-landing&version=xanadu&pubname=xanadu-employee-service-management&ft:locale=en-US).

## UniversalTaskUtils - applyTemplate(String templateSysId, GlideRecord uniTaskGr) {#ariaid-title2}

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](https://www.servicenow.com/docs/access?context=ut-task-template-landing&version=xanadu&pubname=xanadu-employee-service-management&ft:locale=en-US).
{#UniTskUtil-applyTemplate_S_GR__table_c3g_znf_hpb__entry__3}

| Name | Type | Description |
|-|-|-|
| templateSysId | String | Sys_id of universal task template to apply to the specified universal task record. Located in the Universal Task Template \[sn_uni_task_template\] table. |
| uniTaskGr | GlideRecord | GlideRecord of the universal task record to which to apply the template. |
[Table 1. Parameters]

{#UniTskUtil-applyTemplate_S_GR__table_c3g_znf_hpb} {#UniTskUtil-applyTemplate_S_GR__table_d3g_znf_hpb__entry__2}

| Type | Description |
|-|-|
| None | Any errors are written to the system log. |
[Table 2. Returns]

{#UniTskUtil-applyTemplate_S_GR__table_d3g_znf_hpb}  
This code example shows a function that acquires, and then applies, the Feedback
Template.

    (function executeRule(current, previous /*null when async*/) {
      var templateGr = new GlideRecord('sn_uni_task_template');
      templateGr.get('name','Feedback Template');
      var templateSysId = templateGr.getValue('sys_id');
      new sn_uni_task.UniversalTaskUtils().applyTemplate (templateSysId,current);
    })(current, previous);

## UniversalTaskUtils - getActiveChildTasks(String parentSysId) {#ariaid-title3}

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](https://servicenow-prod.fluidtopics.net/Z64TK~kWnpWTEG5bCPvZuQ#c_GlideRecordScopedAPI "The scoped GlideRecord API is used for database operations.") or [global](https://servicenow-prod.fluidtopics.net/nRmUiaC7a08cr2N5iZGqoQ#c_GlideRecordAPI "The GlideRecord API is used for database operations.") depending on the calling
application's scope, to access the returned data, such as using the
getRowCount() method to count active tasks.
{#UniTskUtil-getActiveChildTasks_S__table_sgs_vdf_hpb__entry__3}

| Name | Type | Description |
|-|-|-|
| parentSysId | String | Sys_id of the parent ticket whose active child tickets to return. |
[Table 3. Parameters]

{#UniTskUtil-getActiveChildTasks_S__table_sgs_vdf_hpb} {#UniTskUtil-getActiveChildTasks_S__table_tgs_vdf_hpb__entry__2}

| Type | Description |
|-|-|
| GlideRecord | GlideRecord that contains all active child task records for the specified parent task. |
[Table 4. Returns]

{#UniTskUtil-getActiveChildTasks_S__table_tgs_vdf_hpb}  
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.

    (function executeRule(current, previous /*null when async*/) {
      var gr_ActiveTasks = new sn_uni_task.UniversalTaskUtils().getActiveChildTasks(current.sys_id);
      var count = gr_ActiveTasks.getRowCount();
    })(current, previous);

## UniversalTaskUtils - hasTasksToShow(GlideRecord current) {#ariaid-title4}

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.
{#UniTskUtil-hasTasksToShow_GR__table_kvg_43f_hpb__entry__3}

| Name | Type | Description |
|-|-|-|
| current | GlideRecord | GlideRecord of the parent ticket to check. |
[Table 5. Parameters]

{#UniTskUtil-hasTasksToShow_GR__table_kvg_43f_hpb} {#UniTskUtil-hasTasksToShow_GR__table_lvg_43f_hpb__entry__2}

| 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 |
[Table 6. Returns]

{#UniTskUtil-hasTasksToShow_GR__table_lvg_43f_hpb}  
The following example shows a function that calls this method to check for universal tasks.

    (function executeRule(current, previous /*null when async*/) {
      var sysId = new sn_uni_task.UniversalTaskUtils().hasTasksToShow(current);           
    })(current, previous);

## UniversalTaskUtils - markActiveChildTasksCancelled(String parentSysId) {#ariaid-title5}

Changes the state of all active universal tasks under the specified parent ticket to
"Cancelled".
{#UniTskUtil-markActChildTaskCancel_S__table_z3l_ncf_hpb__entry__3}

| Name | Type | Description |
|-|-|-|
| parentSysId | String | Sys_id of the parent ticket whose active child universal tasks' state should be changed to "Cancelled". |
[Table 7. Parameters]

{#UniTskUtil-markActChildTaskCancel_S__table_z3l_ncf_hpb} {#UniTskUtil-markActChildTaskCancel_S__table_ajl_ncf_hpb__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 8. Returns]

{#UniTskUtil-markActChildTaskCancel_S__table_ajl_ncf_hpb}  
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.

    (function executeRule(current, previous /*null when async*/) {
      new sn_uni_task.UniversalTaskUtils().markActiveChildTasksCancelled(current.sys_id);
    })(current, previous);

## UniversalTaskUtils - markActiveChildTasksCompleted(String parentSysId) {#ariaid-title6}

Changes the state of all active child universal tasks associated with the specified
parent ticket to "Complete".
{#UniTskUtil-markActChildTaskComplete_S__table_pn2_4z2_hpb__entry__3}

| Name | Type | Description |
|-|-|-|
| parentSysId | String | Sys_id of the parent ticket whose active child universal tasks' state should be changed to "Complete". |
[Table 9. Parameters]

{#UniTskUtil-markActChildTaskComplete_S__table_pn2_4z2_hpb} {#UniTskUtil-markActChildTaskComplete_S__table_qn2_4z2_hpb__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 10. Returns]

{#UniTskUtil-markActChildTaskComplete_S__table_qn2_4z2_hpb}  
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.

    (function executeRule(current, previous /*null when async*/) {
      new sn_uni_task.UniversalTaskUtils().markActiveChildTasksCompleted(current.sys_id);
    })(current, previous);


