scripted rest api to query "task_ci" table to get change request number , start date and end_date

Surya007
Tera Contributor

Hi,


I wrote scripted rest api to query "task_ci" table to get change request number , change request start date and end date. Below is complete code for same.


(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var map = [];
var task = new GlideRecord('task_ci');
task.addEncodedQuery('task.sys_class_name=change_request^task.ref_change_request.state=-1');
task.query();
while (task.next()) {
var change = {};
var ciList = [];
var changeId = task.ref_change_request.sys_id;
var affectedCIs = task.ci_item.sys_id;
ciList.push(affectedCIs); //Add new items to the end of the array
change.changeId = changeId;
change.ciList = ciList;
change.start_date = task.ref_change_request.start_date;
change.end_date = task.ref_change_request.end_date;
map.push(change);
}
response.setStatus(200);
response.setContentType('application/json');
response.setBody({
status: 'success',
data: map,
message: 'Task returned changerequest sys id and corresponding effected ci sysid.',
});
})(request, response);


Issue:

a)start date and end date returns empty.

b)Even querying change request number also I am not able to retrieve.


References
https://www.servicenow.com/community/developer-forum/how-do-i-filter-a-gliderecord-query-for-tasks-b...
https://stackoverflow.com/questions/54030626/how-do-i-filter-a-gliderecord-query-for-tasks-by-a-chan...


Any suggestions will be appreciated to retrieve cr number, start_date and end_date by querying task_ci table.

Thanks,
Surya

0 REPLIES 0