All documentation

ServiceNow API Call for Task Relationships

Published April 15, 2024 Guide

User Interface Context

The ServiceNow interface provides a tabbed layout in task forms for organizing various aspects of a task. The "Related Records" tab plays a critical role in displaying associated tasks that are contextually linked to the primary task being viewed. For example, in the Change Management module, it shows change requests that have been established as related, typically indicating a dependency or association necessary for workflow progression.

API Interaction with "Related Records"

The API call to create a task relationship directly impacts the content displayed under the "Related Records" tab within a task form. When a new relationship entry is created through an API call, it programmatically links tasks within the ServiceNow database. The result of this link is visually represented under the "Related Records" tab, where the linked tasks are listed as "Related Items".

Before the API Call

Initially, the "Related Records" tab may not display any related tasks. It indicates that no relationships have been established or that they have not been loaded into the form.

After the API Call

After a successful API call that creates a new relationship, the "Related Records" tab will be updated to display this new link. A new entry will appear, showing the type of relationship and the associated task, including identifiers such as the task number and description.

API Call Details

The following is the curl command template used to create a new task relationship in ServiceNow:

bash
curl -X POST 'https://<ServiceNow_Instance>/api/now/table/task_rel_task' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{
    "type": "Contains::Task of",
    "parent": "<Parent Task Sys ID>",
    "child": "<Child Task Sys ID>"
}' \
-u <User>:<Password>

Post-API Call Verification

Users should be able to visually confirm the creation of the task relationship by navigating to the "Related Records" tab of the relevant task. This update happens dynamically, but it may require a page refresh or re-query of the form to view the latest changes.

Documentation Notes

  • Replace <ServiceNow_Instance>, <Parent Task Sys ID>, <Child Task Sys ID>, <User>, and <Password> with actual information.