Hi All,
I have created a staging table using web service for my ServiceNow Integrtion. Created below Scripted Rest API to receive the payload from a third party. It should create an incident using a staging table and respond to the Incident number in the response body. I am trying to capture the payload data into the staging table and create an incident using a transform map. There seems delay in b/w two entries and it is not responding to the incident number in the response body. But when I compare the created date/time there is no delay. Not sure I am missing something here. Here is my Scripted API code. Can someone help with this?
=============================================
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var requestBody = request.body;
var rquestString = requestBody.dataString;
var parsedBody = JSON.parse(rquestString);
// Extract necessary data from the request body
var shortDescription = parsedBody.short_description || null;
var contact_type = "event";
var u_choice_2 = "Cyber Security";
var category = parsedBody.category;
var description = parsedBody.description;
var caller = parsedBody.caller;
var impact = parsedBody.impact;
var urgency = parsedBody.urgency;
var state = 1;
var assignment_group = parsedBody.assignment_group;
var correlation_id = parsedBody.corrleation_id;
var gr = new GlideRecord('x_*********_integration'); // Staging table name
gr.initialize();
gr.u_short_description = shortDescription;
gr.u_description = description;
gr.u_caller = caller;
gr.u_urgency = urgency;
gr.u_impact = impact;
gr.u_choice_2 = u_choice_2;
gr.u_channel = contact_type;
gr.u_state = state;
gr.u_assignment_group = assignment_group;
gr.u_category = category;
gr.u_correlation_id = correlation_id;
gr.insert(); // Insert the record
var globalUtils = new global.MyGlobalScopeUtils();
globalUtils.sleep(10000); // added some delay to capture incident number
// To get incident number
var incno;
var incRec = new GlideRecord('incident');
incRec.addQuery('sys_id',gr.sys_target_sys_id); // pass the ref sys_id from staging table table to get inc number
incRec.query();
if(incRec.next())
{
incno = incRec.number;
}
// Construct response
var responseBody = {
"status": "success",
"message": "Incident created successfully",
"incident_number": incno, // incident number to respond
"Staging Number": gr.number,// Return the incident number for reference
};
})(request, response);
============================
Thanks
Balaji