REST POST .setStringParameterNoEscape, $(...) - not replaced

lukaspfeiffer
Tera Contributor

Hello community,

 

I try to call an external API with a defined JSON in case an incident is created.

I saw this video: 

#4 Rest Outbound Integration in ServiceNow| Rest Message |Create an Incident in third party tool (https://www.youtube.com/watch?v=YE7jcl-5whs)

this is my code: in the business rule:

 

 

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var request = new sn_ws.RESTMessageV2('RESTTEST','RESTTESTPOST');
	//request.setStringParameterNoEscape('u_caller',current.caller_id);
	//request.setStringParameterNoEscape('u_short_description',current.short_description);

	request.setStringParameterNoEscape('u_sd',current.short_description);
	var response = request.execute();
	var responseBody = response.getBody();
	var statuscode = response.getStatusCode();
	var errorMsg = response.getErrorMessage();

	gs.info("responseBody"+responseBody);

})(current, previous);

 

 

The trigger works fine, the external API is called, but i just see

 

in the text field I want to transmit not the data stored in "current.short_description" in my variable to be replaced (u_sd)

 

REST Message:

"text" : "$(u_sd)".

 

So i would need the value stored in "current.short_description" be transmitted in the REST call and NOT like at the moment the pure placeholder "$(u_sd)". Do I have to build the whole final string to be sent in the business rule code? 

Rest Outbound Integration in ServiceNow| Rest Message |Create an Incident in third party tool Please Like, Share & Subscribe my channel if you find my video useful and do let me know your doubts or queries in comment section below. Instagram : servicenow_adda Gmail : techie.adda123@gmail.com Blog
1 ACCEPTED SOLUTION

@lukaspfeiffer 

Did you create a variable substitution for your placeholder?

If not then it won't work

Variable substitution in outbound REST messages 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@lukaspfeiffer 

it should replace the value in the placeholder

what it is sending currently?

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

lukaspfeiffer
Tera Contributor

@Ankur Bawiskar  this for your reply.

Indeed it is just the pure placeholder that is transmitted in the message. But in contrast to the example in the video I referred to in my previous post my JSON structure is more nested. It is from an SMS API.

You see the relevant data field is the "text" field.

However, might there be some other setting to be changed such that in the string the $(...) is recognized as a placeholder?

Or should I put all the JSON Content into the JavaScript based Rule and try to hand over just the final version of the JSON to the content field in the HTTP Request. But of course I don't know how this would be done...

{
  "options" : {
  "src" : "SMSTest",
  },
  "messages" : [ {
  "text" :  "$(u_sd)",  
  "recipients" : [ {
  "dst" : "+49176123456"
  }]
  }
  ]
}

 

lukaspfeiffer
Tera Contributor

@Ankur Bawiskar : Any possibility on your side to reproduce this phenomenon that the "placeholder" is not replaced by the desired value in such a REST call? Having just the string with the placeholder transmitted is of course not a valid solution.

@lukaspfeiffer 

Did you create a variable substitution for your placeholder?

If not then it won't work

Variable substitution in outbound REST messages 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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