The CreatorCon Call for Content is officially open! Get started here.

Rest Message via Patch Method not working

nomadie
Kilo Expert

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..

5 REPLIES 5

Ashutosh Munot1
Kilo Patron
Kilo Patron
Hi, Have you created a rest message for this? Can you check what have you selected there? Thanks, Ashutosh

Yes I have.. Using the test values, it was successfully sent through..

find_real_file.png

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

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');