How to escape special characters
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2018 06:48 AM
Hi All,
I am sending the json to 3rd party system. So using the BR i was forming it this way -
var r = new sn_ws.RESTMessageV2('Creation', 'Default PUT');
r.setStringParameterNoEscape('adhocID', current.number);
r.setStringParameterNoEscape('fieldid', current.field_id);
r.setStringParameterNoEscape('state', stateVal);
r.setStringParameterNoEscape('worknote', current.work_notes));
r.setStringParameterNoEscape('group', current.assignment_group.getDisplayValue());
r.setStringParameterNoEscape('closed', current.closed_at);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
I get an error message as the "Record was misformed" when the worknote is typed as-
ASU, Test
testasu
CN=tyty\, fgt,OU=CGS Users,DC=tester,DC=cvs
Wednesday, December 27, 2017 12:19:12 PM
How can i escape the speacial characters or any issue with this and get it working?
Thanks
Surya
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2018 09:06 AM
I also changed r.setStringParameter('worknote', current.work_notes); you had extra ) at the end
Did you tried my script ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2018 09:14 AM
Hi
I still see the issue. 😞
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2018 09:45 AM
Hi mike,
I do combine all the worknotes and mention that in place of current.work_notes. basically when its just current.work_notes it do work. But when i add all worknotes and comments and send it , then it is showing 400 or 404 error. Please advise.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2018 10:03 AM
This is my script which i am using -
function jsonEncode(str) {
str = new JSON().encode(str);
return str.substring(1, str.length - 1);
}
(function executeRule(current, previous /*null when async*/) {
var notes=[];
var gr = new GlideRecord('sys_journal_field');
gr.addEncodedQuery("element=comments^ORelement=work_notes");
gr.addQuery('element_id',current.sys_id);
gr.orderByDesc('sys_created_on');
gr.query();
while(gr.next()){
notes +=(gr.sys_created_on + ' - ' + gr.sys_created_by + ' ' + gr.element + '- ' + gr.value + "<br>").replace(/"/g,'\\"');
gs.addInfoMessage(notes);
}
var json = new JSON();
var r = new sn_ws.RESTMessageV2('Creation', 'Default PUT');
r.setStringParameter('ID', current.number);
r.setStringParameter('state', stateVal);
r.setStringParameter('worknote', jsonEncode(notes + ''));
r.setStringParameter('group', current.assignment_group.getDisplayValue());
r.setStringParameter('closed', current.closed_at);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2018 10:13 AM
change below
notes.push((gr.sys_created_on + ' - ' + gr.sys_created_by + ' ' + gr.element + '- ' + gr.value + "<br>").replace(/"/g,'\\"'));