How to send the state "resolved" along with resolution note and resolution code to 3rd party
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2024 08:54 PM
I have a bi directional integration between my ServiceNow and 3rd party ServiceNow for incident record.
As per the requirement when if we resolve incident at my side then it should send the payload to containing the state , resolution note and resolution code to 3rd party in JASON format so that they can resolve the incident at their end too.
However My whole code is working except this one only where i am trying to send these 3 values to 3rd party.
I Below is my code of BR, please suggest what change i should so that it can send the information in correct format.
(function executeRule(current, previous /*null when async*/ ) {
if (current.u_external_ticket_no == '') {
try {
var rInsert = new sn_ws.RESTMessageV2('Ultima', 'Create Incident');
var descbody = new TranslateTexttoen().translate(current.description);//current.description; // added by Translation team to convert non english text to english
descbody = descbody.replace(/(\r\n|\n|\r|\\n)/gm, "");
descbody = JSON.stringify(descbody);
descbody = descbody.replace(/"/g, "'");
descbody = descbody.replace(/\\/g, "\\\\");
var shortDesc = new TranslateTexttoen().translate(current.short_description);//current.short_description; // added by Translation team to convert non english text to english
shortDesc = shortDesc.replace(/(\r\n|\n|\r|\\n)/gm, "");
shortDesc = JSON.stringify(shortDesc);
shortDesc = shortDesc.replace(/"/g, "'");
shortDesc = shortDesc.replace(/\\/g, "\\\\");
rInsert.setStringParameterNoEscape('short_description', shortDesc);
rInsert.setStringParameterNoEscape('description', descbody);
rInsert.setStringParameterNoEscape('caller_id', 'Costa_API_user');
rInsert.setStringParameterNoEscape('impact', current.impact);
rInsert.setStringParameterNoEscape('urgency', current.urgency);
rInsert.setStringParameterNoEscape('state', 1);
rInsert.setStringParameterNoEscape('contact_type', 'Integration');
rInsert.setStringParameterNoEscape('category', '910'); // cloud
rInsert.setStringParameterNoEscape('subcategory', '1015'); // virtual
rInsert.setStringParameterNoEscape('u_customer_reference', current.number);
var insertResponse = rInsert.execute();
var insertResponseBody = insertResponse.getBody();
var insertHttpStatus = insertResponse.getStatusCode();
var parsedData = JSON.parse(insertResponseBody);
gs.log(parsedData.result.number + " Ultima Incident creation response : " + insertResponseBody, 'UltimaINCInsert');
current.u_external_ticket_no = parsedData.result.number;
current.state =11;
current.update();
} catch (ex) {
var message = ex.message;
}
} else {
try {
var rUpdate = new sn_ws.RESTMessageV2('Ultima', 'Update Incident');
var req = {};
req.u_customer_reference = current.number.toString();
if (current.impact.changes()){
//req = req + ',"impact":"' + current.impact + '"';
req.impact = current.impact.toString();
}
if (current.urgency.changes())
//req = req + ',"urgency":"' + current.urgency + '"';
req.urgency = current.urgency.toString();
if (current.work_notes.changes()) {
var worknotes1 = new TranslateTexttoen().translatewn('incident', current.sys_id,'work_notes'); // added by Translation team to convert non english text to english
var workNotes =current.work_notes.getJournalEntry(1);
workNotes = workNotes.replace(/(\r\n|\n|\r|\\n)/gm, "");
workNotes = JSON.stringify(workNotes);
workNotes = workNotes.replace(/"/g, "'");
workNotes = workNotes.replace(/\\/g, "\\\\");
//req = req + ',"work_notes":"' + workNotes + '"';
req.work_notes = worknotes1;
}
if (current.comments.changes()) {
var comment = current.comments.getJournalEntry(1);
var comment1 = new TranslateTexttoen().translatewn('incident', current.sys_id,'comments'); // added by Translation team to convert non english text to english
comment = comment.replace(/(\r\n|\n|\r|\\n)/gm, "");
comment = JSON.stringify(comment);
comment = comment.replace(/"/g, "");
comment = comment.replace(/\\/g, "\\\\");
//req = req + ',"comments":"' + comment + '"';
req.comments = comment1;
}
if (current.assignment_group.changes()) {
if (current.assignment_group == 'e8c3483c1b118510f48c65f7b04bcb0d') { // Ultima support group
//req = req + ',"assignment_group":"' + 'd934315d1b4a2300ab0887fe6e4bcbf5' + '"'; // ultima servicedesk 24*7 req.asign = sysid
req.assignment_group = 'd934315d1b4a2300ab0887fe6e4bcbf5';
}
// else {
// req = req + ',"state":"' + '8' + '","close_code":"' + 'Cancelled' + '","close_notes":"' + 'Cancelled as reassigned' + '"'; // resolved with cancel code in IBM
}
if (current.state.changes()) {
if (current.state.changesTo('2')) { // In Progress
//req = req + ',"state":"' + '2' + '"';
req.state = current.state.toString();
}
else if (current.state.changesTo('6')) { // resolved
//req.state = current.state.toString();
//req += "Incident is Resolved at Costa End with Resolution Code - " + current.close_code + "and Resolution Note - " + current.close_notes + "state - " + current.state.toString() ;
req.state = "close_code " + ": " + current.close_code + "," + "close_notes " + ": " + current.close_notes + "," + " state " + ": " + current.state.toString();
//req = req + ',"state":"' + '6' + '","close_code":"' + close_code + '","close_notes":"' + closeNotes + '"';
//req.state = ',"state":"' + '6' + '","close_code":"' + close_code + '","close_notes":"' + closeNotes + '"';
gs.log('Testing by vikas mishra' + req.state);
} else if (current.state.changesTo('7')) { // closed
//req = req + ',"state":"' + '7' + '"';
req.state = '7';
} else if (current.state.changesTo('8')) { // cancelled
//req = req + ',"state":"' + '8' + '"';
req.state = '8';
} else if (current.state.changesTo('13')) { //reopened
req = req + ',"state":"' + '2' + '","work_notes":"' + 'Reopened' + '"';
gs.log("reopened" + req);
} else {
gs.log(current.state + " state update is not in scope", 'ultimaINCUpdate');
}
}
//req = req + '}';
gs.log("Update req body " + JSON.stringify(req), 'ultimaINCUpdate');
// rUpdate.setStringParameterNoEscape('request', JSON.stringify(req));
rUpdate.setRequestBody(JSON.stringify(req));
var updateResponse = rUpdate.execute();
var updateResponseBody = updateResponse.getBody();
var updateHttpStatus = updateResponse.getStatusCode();
gs.log('testing req ' + '' + req);
gs.log('testing updateResponseBody ' + '' + updateResponseBody);
gs.log('testing updateHttpStatus ' + '' + updateHttpStatus);
gs.log(" Ultima Incident update response : " + updateResponseBody, 'ultimaINCUpdate');
} catch (ex) {
message = ex.message;
}
}
})(current, previous);
0 REPLIES 0