Rest Message via Patch Method not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-11-2019 09:33 AM
Asking help from SN gurus on what's wrong with I'm doing.
Scenario: We will need to send additional comments from 1 SN instance to another SN instance using a correlation_id
Rest message - Patch method: test value are successfully sent over.
Business Rule - failing
When to run: After / Update
Condition: Additional comments changes
(function executeRule(current, previous /*null when async*/) {
gs.log('In Business Rule New Run', 'ebond');
try {
gs.log('start here', 'ebond');
var r = new sn_ws.RESTMessageV2('Ebond', 'Patch Ebond');
r.setStringParameterNoEscape('sys_id', '81846c281b3b3b409fc9fee58d4bcb71'); //correlation_id
r.setStringParameterNoEscape('comments', 'BR message starts here');
//override authentication profile
//authentication type ='basic'/ 'oauth2'
//r.setAuthenticationProfile('authentication_type', 'basic_auth_profile');
//set a MID server name if one wants to run the message on MID
//r.setMIDServer('MY_MID_SERVER');
//if the message is configured to communicate through ECC queue, either
//by setting a MID server or calling executeAsync, one needs to set skip_sensor
//to true. Otherwise, one may get an intermittent error that the response body is null
//r.setEccParameter('skip_sensor', true);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.log('HTTP Status : ' + httpStatus,'ebond');
}
catch(ex) {
var message = ex.message;
}
gs.log("End Business Rule", 'ebond');
})(current, previous);
Can anyone take a look at this please..
- Labels:
-
Integrations
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-11-2019 09:40 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-11-2019 09:52 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-11-2019 09:57 AM
Hi,
what error you are getting? can you share here?
Mark ā
Correct if this solves your issue and also mark š Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-12-2019 02:59 AM
Corrected my script and I was able to run this successfully. However, when I dynamically use the correlation_id and additional comments. it didn't log any values. What's wrong with my variable declarations?
(function executeRule(current, previous /*null when async*/) {
// Condition is : current.correlation_idISNOTEMPTY
gs.log('In Business Rule New Run', 'check');
try {
comment = current.comments;
corID = current.correlation_id;
gs.log('Comment : ' + comment, 'check');
gs.log('Cor ID : ' + codID, 'check');
var r = new sn_ws.RESTMessageV2('Ebond', 'Patch Ebond');
r.setStringParameterNoEscape('correlation_id', corID);
r.setStringParameterNoEscape('comments',comment);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.log('HTTP Status : ' + httpStatus,'check');
}
catch(ex) {
var message = ex.message;
}
gs.log("End Business Rule", 'check');