- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2022 08:36 AM
Afternoon all
Hoping someone with a bit more coding/scripting chops could point our where I can fix my issue. So I have a rest api call that is sending Incident data when incident is created to another customer instance. Its working fine when 'Short description' and 'Description' has plain text in there but its failing when someone pastes this text into the description.
Thanks all
Business rule script-
(function executeRule(current, previous /*null when async*/ ) {
function jsonEncode(str) {
str = new JSON().encode(str);
return str.substring(1, str.length - 1);
}
try {
var r = new sn_ws.RESTMessageV2('Integration', 'Create Incident');
var desc = current.description.replace(/(\r\n|\n|\r)/gm, ",");
var ci_loc = current.cmdb_ci.location;
r.setStringParameterNoEscape('desc', desc);
//r.setStringParameterNoEscape('desc', jsonEncode(current.description + ''));
r.setStringParameterNoEscape('short_desc', current.short_description);
r.setStringParameterNoEscape('comments', current.comments);
r.setStringParameterNoEscape('cor_id', current.sys_id);
r.setStringParameterNoEscape('cust_ref', current.number);
r.setStringParameterNoEscape('priority', current.priority);
//r.setStringParameterNoEscape('notes', current.work_notes); -
r.setStringParameterNoEscape('ci', current.cmdb_ci.getDisplayValue());
var response = r.execute();
var responseBody = response.getBody();
var obj = JSON.parse(responseBody); // define JSON parsing for reponse JSON file to decode
var foundsysID = obj.result.sys_target_sys_id.value; //decoded newly created incident sys_id
current.correlation_id = foundsysID; //copied the number of 3rd incident to correlation id
var number = obj.result.u_number; // decoded 3rd party newly created incident number
current.u_customer_ref = number;
var httpStatus = response.getStatusCode();
gs.log('>>>>> Create Incident BR = ' + httpStatus + ' - ' + responseBody);
} catch (ex) {
var message = ex.message;
}
})(current, previous);
Text copied into the descripton field via servicedesk which causes a failure in the logs of '400 - {"error":{"message":"Exception while reading request","detail":"The payload is not valid JSON."},"status":"failure"}
The following vendors have released security updates to address multiple vulnerabilities:
Palo Alto Networks Security Advisory CC-4191
Ivanti/Pulse Secure Security Advisory CC-4193
Oracle Critical Patch Update Advisory CC-4194
Cisco Security Advisories CC-4195
Adobe Security Bulletin CC-4196
F5 Security Advisory CC-4197
Affected organisations are encouraged to review the following vendor security advisories and apply any relevant updates or mitigations:
Palo Alto Networks Security Advisory CVE-2022-0030
Ivanti's Pulse Secure Security Update SA45520
Oracle October 2022 Critical Patch Update Advisory
Cisco Security Advisories:
cisco-sa-meraki-mx-vpn-dos-vnESbgBf
cisco-sa-ise-path-trav-Dz5dpzyM
cisco-sa-jabber-xmpp-Ne9SCM
cisco-sa-roomos-trav-beFvCcyu
cisco-sa-ise-xss-twLnpy3M
Adobe Security Updates: Illustrator | APSB22-56
F5 Security Advisory K30425568: Overview of F5 vulnerabilities (October 2022)
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2022 11:15 PM
Seemed to of got it working by doing this-
r.setStringParameterNoEscape('desc', jsonEncode(current.description + ''));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2022 12:20 PM
Hi, an example of the payload would have provided the easiest way to assess your issue and without one there is no simple way to evaluate.
Based on your description and the code provided, perhaps the problem is with the content of the description field and\or the regex manipulation - is there any reason why you are removing line terminators?
Perhaps you could test without the regex expression and a single line in the description field?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2022 09:24 PM
Yes so thats exactly what I have said, it works fine with simple text placed into the description. It fails when it says it has invalid character's placed into the description.
Im trying to see if there is some is something I can do to allow it to send with the text example provided.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2022 01:00 PM
Hi,
it would be helpful to show the REST Message configuration where the variable 'desc' is used.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2022 09:28 PM
Hi BigZolo. Thanks for taking the time to respond.
Here are some screen shots of the rest message.