Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Please explain setStringParameterNoEscape() with example.

smruti
Kilo Contributor

An AFTER business rule is written to send SMS through REST API as written below.

function triggerSMS()

{

  var r = new RESTMessage('SMS', 'get');

  r.setStringParameter('mnumber',current.u_recipient_number);

    r.setStringParameter('message', current.u_message);

  var response = r.execute();

  gs.log(current.u_recipient_number+' ,Execution Response:'+response.getBody());

}

This business rule is executing properly. But If message contains reserved character as & gets converted to equivalent escaped character as &

To avoid this issue if I write

  r.setStringParameterNoEscape('message', current.u_message);

It is not working properly .

In log I got   below information and I didnt receive SMS aswell.If also the message doesnt contain XML reserved character also.

msg.png

How to use setStringParameterNoEscape() with example please and how to prevent & converting to & .

Its not jelly script.


Thanks in advance.

2 REPLIES 2

smruti
Kilo Contributor

Any answer?


Ripu Daman1
Tera Expert

Here is the solution:

Lets suppose you are trying to send contents of current.u_message:

escapedMessageToSend = new JSON().encode(current.u_message);

escapedMessageToSend = escapedMessageToSend.substring(1, escapedMessageToSend.length - 1);//remove the quotes added around the string by encode function
escapedMessageToSend = escapedMessageToSend.replace(/\\n/g, "<br>"); //depending on business logic you could replace newline characters with html br or just remove the special chars

r.setStringParameterNoEscape('message', escapedMessageToSend );

 

 

Please mark the response helpful/correct if it helps answer your question.