How can I send values to Rest API with new line and special characters??

Kunal33
Tera Expert

We are sending variables from Instance A to the description of Instance B, Please find the below code as we are unable to send the variables in separate line. Please help to solve the issue.

 

// Storing variables 
var variables = current.variables.getElements();
var variabledata = '';
for (var i = 0; i < variables.length; i++) {
var question = variables[i].getQuestion();
variabledata += question.getLabel() + ":" + question.getDisplayValue()+'' + "\n "; // Storing variables in separate lines

}

function escapeSpecialChars(jsonString) {
return jsonString.replace(/(\r\n|\n|\r|\t|\"|\\)/gm, "");
}
r.setStringParameterNoEscape('description', escapeSpecialChars(variabledata) ); 

 

Result:

 "description" : "Requested By:joshi  Requester For:joshi kallakunta Email ID:joshi.kallakunt Short Description:test Description:test Source:Web ".