Comment is going on next line
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2023 08:40 PM
Hi,
We have a requirement on the integration send the additional comment into the same line from ServiceNow instance to another tool when update the additional comment in incident.
The issue we are facing is that there are additional comments s, which are going new lines. Example "comments": "20230105 101428 Mohammed Additional Comments
test ",
it should be as go as "comments": "20230105 101428 Mohammed Additional Comments test ",
we are using this script
(function executeRule(current, previous /*null when async*/) {
try {
var r = new sn_ws.RESTMessageV2('Elasticops', 'post data');
if(current.comments.changes()){
var com=current.comments.getJournalEntry(1);
var com1 = com.replace(/[^\w\s]/gi, '');
var com2 = com1.replace(/\s{2,10}/g, ' ');
r.setStringParameterNoEscape('comments', com2);
}
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.log(r.getRequestBody(), "ACTReqbodyupd");
gs.log(httpStatus + responseBody, "ACTResbodyupd");
if(httpStatus != 202){
gs.eventQueue("eops.update", current, responseBody, httpStatus);
}
}
catch(ex) {
var message = ex.message;
}
})(current, previous);
Here is the logs:
{
"incident_state": "1",
"u_sub_status": "",
"category": "",
"subcategory": "",
"short_description": "",
"description": "",
"work_notes": "",
"comments": "20230105 101428 Mohammed Additional Comments
test ",
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2023 04:45 AM
You could try JSON stringify-ing the value:
r.setStringParameterNoEscape('comments', JSON.stringify(com2));
but in that case you have to remove the surrounding quotes from the template string:
"comments": ${comments},
vs. currently:
"comments": "${comments}",
as JSON.stringify() add those quotes too.