We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Through REST API, How to get RITM and Task values for each Request?

soibam_ana_sing
Giga Contributor

we are integration SNOW with third party platform " Hybrid cloud management" through REST APIs. we use only REST APIs for integration. 

We order Catalog Items through Service catalog APIs(https://docs.servicenow.com/bundle/istanbul-servicenow-platform/page/integrate/inbound-rest/reference/r_SCatAPIAddItemToCartPOST.html#ariaid-title12)  and a request is generated (REQ0010180). Through REST APIs, How would I get RITM and Task values for each Request? 

we don't want to use  client script gliderecord

 

regards

Soibam

6 REPLIES 6

thank you very much. great help.

Hitoshi Ozawa
Giga Sage

Can create a Scripted REST API to get everything in 1 REST call.

(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
    var number = request.pathParams.number;

    var taskInfo = {};
    try {
        var grRTIM = new GlideRecord('sc_req_item');
        if (grRTIM.get('number', number)) {
            taskInfo = {
                'number': number.toString(),
                'item': grRTIM.cat_item.name.toString(),
                'stage': grRTIM.stage.toString(),
                'request': grRTIM.request.number.toString(),
                'requested_for': grRTIM.requested_for.name.toString(),
                'opened_by': grRTIM.opened_by.name.toString(),
                'due_date': grRTIM.due_date.toString(),
                'updated': grRTIM.sys_updated_on.toString()
            };
            var grTask = new GlideRecord('sc_task');
            grTask.addQuery('parent', grRTIM.sys_id);
            grTask.query();
            var taskList = [];
            while (grTask.next()) {
                var taskNumber = grTask.number;
                var taskPriority = grTask.priority;
                taskList.push({
                    'number': grTask.number.toString(),
                    'priority': grTask.priority.toString(),
                    'state': grTask.state.toString(),
                    'short_description': grTask.short_description.toString(),
                    'assignment_group': grTask.assignment_group.name.toString(),
                    'opened': grTask.opened_at.toString()
                });

            }
            //gs.info(JSON.stringify(taskList));
            taskInfo['tasks'] = taskList;
        }
    } catch (e) {
        gs.error("ERROR=", e);
    }
    return taskInfo;
})(request, response);

Example result:

{
  "result": {
    "number": "RITM0010040",
    "item": "mrvs script",
    "stage": "Assess or Scope Task",
    "request": "REQ0010033",
    "requested_for": "System Administrator",
    "opened_by": "System Administrator",
    "due_date": "2020-10-06 09:10:08",
    "updated": "2020-10-04 09:10:10",
    "tasks": [
      {
        "number": "SCTASK0010059",
        "priority": "4",
        "state": "-5",
        "short_description": "Provide requested service",
        "assignment_group": "Software",
        "opened": "2020-10-04 09:10:09"
      },
      {
        "number": "SCTASK0010058",
        "priority": "4",
        "state": "1",
        "short_description": "Assess or Scope Task",
        "assignment_group": "Field Services",
        "opened": "2020-10-04 09:10:08"
      }
    ]
  }
}