Change Request API

jerinjose93
Kilo Contributor

Hey guys , i am trying to retrieve the impacted services info for the change request. I tried to pull data from task_ci and task_cmdb_ci_service but the results don't seem to be matching with what I see in the ui . 

Any suggestions pls?

1 REPLY 1

Bhavya11
Kilo Patron

Hi @jerinjose93 ,

 

try with below way

1. Create Scripted rest API's 

2. Create resource with HTTP method Get 

Bhavya11_0-1766472633361.png

 

 

3. in script try something like this 

(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {

var changeId = request.queryParams.change_id;

var cu = new ChangeUtils();
cu.refreshImpactedServices(changeId);

var impacted = [];
var affected= []
var gr = new GlideRecord('task_cmdb_ci_service');
gr.addQuery('task', changeId);
gr.query();

while (gr.next()) {
    impacted.push({
        "service_name": gr.cmdb_ci_service.getDisplayValue(),
        "service_id": gr.getValue('cmdb_ci_service')
    });
}

var gr = new GlideRecord('task_ci');
gr.addQuery('task', changeId);
gr.query();

while (gr.next()) {
    affected.push({
        "affected_name": gr.ci_item.getDisplayValue(),
        "service_id": gr.getValue('ci_item')
    });
}


return {
    "impacted_services": impacted,
    "affected_name": affected
};
})(request, response);

 

4. save the record and click on Explore REST API

5. Test with the change record 

 

Bhavya11_1-1766472772070.png

6. JSON response will have 

{
  "result": {
    "impacted_services": [
      {
        "service_name": "Email",
        "service_id": "27d32778c0a8000b00db970eeaa60f16"
      }
    ],
    "affected_name": [
      {
        "affected_name": "*BUD-IBM",
        "service_id": "53fdbc8437201000deeabfc8bcbe5d10"
      }
    ]
  }
}

 

 

If this information proves useful, kindly mark it as helpful or accepted solution.

 

Thanks,

BK

If this information proves useful, kindly mark it as helpful or accepted solution.

Thanks,
BK