- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2022 07:14 AM
Hi,
I'm working on REST API integration and I've created form and also Business rule for "Create Incident" process,
but now I have to create also "update incident" process and here I have a problem. Cause I have a script and definitely something is not working properly... I've created new field in a incident form "u_isd_ticket" and now I want to get number value from another platform to this field. the target field is "correlation_number", waht do you think how to correct a script code?
(Other form value:
When - async
checkbox UPDATE = true
and also condition for assignment group)
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2022 08:09 AM
Hi @DIVI1 ,
Try below code
(function executeRule(current, previous /*null when async*/ ) {
var ticketcmdb = 'GFP 0020764392 000';
var ticketcat = 'Human Resources Payroll';
var r = new sn_ws.RESTMessageV2('NTT API Integration', 'NTT POST');
r.setStringParameterNoEscape('u_description', current.description);
r.setStringParameterNoEscape('u_short_description', current.short_description);
r.setStringParameterNoEscape('u_state', current.state.getDisplayValue());
r.setStringParameterNoEscape('u_priority', current.priority);
r.setStringParameterNoEscape('u_system', ticketcmdb);
r.setStringParameterNoEscape('u_category', ticketcat);
r.setStringParameterNoEscape('u_number', current.number);
r.setStringParameterNoEscape('u_comments', current.comments);
r.setStringParameterNoEscape('u_work_notes', current.work_notes);
r.setStringParameterNoEscape('u_assignment_group', 'SAP');
r.setStringParameterNoEscape('u_correlation_number', current.isp_ticket);
var response = r.execute();
var responseBody = response.getBody();
var statusocde = response.getStatusCode();
var errormsg = response.getErrorMessage();
gs.info("responseBody" + responseBody);
var responseObj = JSON.parse(responseBody);
gs.info("Correlation number check " + responseObj.correlation_number);
current.u_isp_ticket = responseObj.correlation_number;
current.work_notes = "information: Ticket successful created. Ticket number: " + responseObj.correlation_number;
current.update();
})(current, previous);
Still if you are facing share the logs and check what values you are receiving
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2022 07:18 AM
I've got confirmation of sending and also receiving ticket in an external platform in a system logs also I can see there a value of correlation_number which is necessary for me to implement it to isd_ticket field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2022 07:20 AM
But these logs are form "create incident" form created by another business rule.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2022 07:33 AM
Hi @DIVI1 ,
Don't share only screenshot. share script that you are working that will help a lot to provide solution.
Hope you will share script as well in future.
on your script No need to use GlideRecord because business rule is on incident table. you can use current object to update data.
Refer below code and replace with your fieldnames.
current.u_isd_tiket= responseObj.correlation_number;
current.work_notes="NTT infomation: Ticket successful created. Ticket Number: "+responceObj.correlation_number;
current.update();
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2022 07:47 AM
Thanks it's not working yet.
I've got logs like:
responseBody{"action":"AddInfoResponse","PersonMaps":{"item":{"PersonId":"0000036641","PersonIdExt":"0000036641"}}}
after creating incident I reveiving logs like:
responseBody{"action":"ProcessIncidentResponse","PersonMaps":{"item":{"PersonId":"0000036641","PersonIdExt":"0000036641"}},"correlation_number":"9000809481"}
And the full script of Update incident:
(function executeRule(current, previous /*null when async*/) {
{
var ticketcmdb = 'GFP 0020764392 000';
var ticketcat = 'Human Resources Payroll';
var r = new sn_ws.RESTMessageV2('NTT API Integration','NTT POST');
r.setStringParameterNoEscape('u_description', current.description);
r.setStringParameterNoEscape('u_short_description', current.short_description);
r.setStringParameterNoEscape('u_state', current.state.getDisplayValue());
r.setStringParameterNoEscape('u_priority', current.priority);
r.setStringParameterNoEscape('u_system', ticketcmdb);
r.setStringParameterNoEscape('u_category', ticketcat);
r.setStringParameterNoEscape('u_number', current.number);
r.setStringParameterNoEscape('u_comments', current.comments);
r.setStringParameterNoEscape('u_work_notes', current.work_notes);
r.setStringParameterNoEscape('u_assignment_group', 'SAP');
r.setStringParameterNoEscape('u_correlation_number', current.isp_ticket);
var response = r.execute();
var responseBody = response.getBody();
var statusocde = response.getStatusCode();
var errormsg = response.getErrorMessage();
gs.info("responseBody"+responseBody);
(function(response) {
var responseObj = JSON.parse(response);
current.u_isp_ticket = responseObj.correlation_number;
current.work_notes = "information: Ticket successful created. Ticket number: " + responseObj.correlation_number;
current.update();
});
}
})(current, previous);