I am trying to rest API request body as "fieldname" : "RS${env}Test" but the ${env} part is getting ignored while sending. If I try to use html encoding, destination not able to decode it. What is the possible way to send the request body?

Utsab
Tera Contributor

I want to pass below job names as an Input request of PUT method of REST message which is in JSON format having “${env}” in the name of Jobs. It is observed after sending the request, “${env}” gets ignored and third party application database gets updated as RHDEM_****
Correct Job name : RH${env}DEM_****
Changed job name : RHDEM_****

1 ACCEPTED SOLUTION

UtsabGiri
Mega Expert

Got a reply from HI Team, this function is OOTB and can't be avoided. We can only replace the special characters by HTML encoding and it has to be decoded at client end.

View solution in original post

6 REPLIES 6

palanikumar
Mega Sage

Hi,

${variable_name} is used by ServiceNow to pass dynamic value. Since you are not passing value, servicenow might think it is blank. Add this line in your code before r.execute() and see whether issue is resolved

r.setStringParameterNoEscape('name', '${name}');
Thank you,
Palani

Tried this - "name": "RM'${env}'USD_XXXX"

But this was not working. 

Can you share the current code? I can check and confirm

 

Thank you,

Palani

Thank you,
Palani

var PUTinput = {"name":"RH${env}DEM_XXXX","emailNotifications":[],"setVariableActions":[]}

 

NOTE = Request Body contains about 300 fields. For sample I have put 3. Below is PUT function called from the script include.

 

resData = this.jobDefinition3(PUTinput ));

 

jobDefinition3: function(getResponse) {
var r = new sn_ws.RESTMessageV2('XXXX.Release_Integration', 'PUT');
r.setRequestBody(getResponse);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
return responseBody;
},