How can I send values to Rest API with new line and special characters??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2022 06:50 AM
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 ".

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2022 11:40 PM
Hi Kunal,
You can the below example to send the values in next line in Rest API.
function jsonEncode(str) {
str = new JSON().encode(str);
return str.substring(1, str.length - 1);
}
var description = "Contacting Customer Name: " + current.caller_id.getDisplayValue() + "\nContact Number: " + current.caller_id.mobile_phone + "\nCategory: " + current.category + "\nSubcategory: " + current.subcategory + "\nAffected Service: " + current.business_service.getDisplayValue() + "\nDescription: " + current.description;
r.setStringParameterNoEscape('description', jsonEncode(description + ''));
Thanks
Sai Krishna
Kindly mark the answer as correct/helpful if it solves your issue.