REST API script creating task twice for particular assignment group

Shree Nag
Tera Expert

Hello,

Appreciate your help in advance.

 

I have scripted API that is for creating 2 catalog tasks for 2 assignment groups(lets call it A & B) for a requested Item from an integration.

While the  two catalog tasks is being created for both A & B assignment group,  once the catalog task on A is closed complete, another one is being created for assignment group A, with no short description or description.

The catalog task created for assignment group B is closing without creating another duplicate.

 

I need to stop the second catalog task being created for assignment group A

 

This is happening only for requests created through this third party integration requests.

I have posted the RESP API scripts here, please help me point why there is second task created for assignment A after being closed complete and what should be corrected to prevent it from being created.

 

(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
 
var currentDate = new GlideDateTime();
currentDate.addDays(3);
 
   var gr = new GlideRecord('sc_request');
   gr.initialize();
 
   gr.requested_for = 'sys_id of service account' //'svc snow-sailpt' Service account suys id
   gr.short_description = request.body.data.short_description;
   gr.description = request.body.data.Description;
   gr.due_date = currentDate;
   gr.state = 1;
 
var requestSysId = gr.insert();
var requestNum = gr.number;
 
var reqItem = new GlideRecord('sc_req_item');
reqItem.initialize();
reqItem.request = requestSysId;
reqItem.cat_item = 'sys_id of request catalog';
reqItem.short_description = request.body.data.short_description;
reqItem.description = request.body.data.Description;
reqItem.due_date = currentDate;
var ritmSysId = reqItem.insert();
 
 
gs.info('Created request with sysID: requestSysId');
 
// catalog task for Assignment group A
var catTaskSD = new GlideRecord('sc_task');
catTaskSD.initialize();
catTaskSD.request = requestSysId;
catTaskSD.request_item = ritmSysId;
catTaskSD.u_requested_for = 'sys_id of service account';
 
catTaskSD.short_description = request.body.data.short_description;
catTaskSD.description = request.body.data.Description;
catTaskSD.assignment_group = 'Assignment group A';
 
catTaskSD.due_date = currentDate;
var taskSysId = catTaskSD.insert();
 
// catalog task for Assignment Group B
var catTaskOHCM = new GlideRecord('sc_task');
catTaskOHCM.initialize();
catTaskOHCM.request = requestSysId;
catTaskOHCM.request_item = ritmSysId;
catTaskOHCM.u_requested_for = 'sys_id of service account';
//catTask.short_description = request.body.data.short_description;
catTaskOHCM.short_description = request.body.data.short_description;
catTaskOHCM.description = request.body.data.Description;
 
catTaskOHCM.assignment_group = 'Assignment group B';
catTaskOHCM.due_date = currentDate;
var taskSysId2 = catTaskOHCM.insert();
 
 
if (requestSysId) {
        response.setStatus(201);  // Created
        response.setBody({ message: "Request "+requestNum+" created sucessfully." });
    } else {
        response.setStatus(500);  // Internal Server Error
        response.setBody({ error: "Failed to create request." });
    }
gs.info('Request Body: ' + JSON.stringify(request.body)); 
 
})(request, response);
0 REPLIES 0