- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2014 06:12 PM
There is a REST message defined in Service Now.
The POST call in the REST message has a variable ${content} in its content field.
And a REST Message Function Parameter called "content" is defined with a valid JSON as string:
{"result":{"upon_approval":"proceed","reason":"",................................
But, testing this service shows that all quotes in the JSON above are escaped. Input content sent to the REST Message call looks like this:
{"result":{"upon_approval".................................
Is there a way to avoid this auto escape? I faced the same problem when I tried to call this REST message from a script too.
Some of the options I tried in the script:
JSONParser(), JSON.encode()
Message was edited by: M G
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2014 07:47 PM
Hey,
I have checked a REST message that uses JSON in my system and here is a snippet, maybe this will help. This posts incidents to Jira..
So we start but running a business rule and create an object...
var issue = new Object();
issue.fields = new Object();
issue.fields.project = new Object();
issue.fields.project.key = gs.getProperty("com.snc.integration.jira.project");
issue.fields.summary = ""+current.short_description;
issue.fields.issuetype = new Object();
issue.fields.customfield_10025 = ""+current.number;
issue.fields.issuetype.name=""+current.subcategory;
issue.fields['customfield_'+j.sysidField] = j.getSysIdPrefix()+":"+current.sys_id;
issue.fields.priority = new Object();
issue.fields.priority.id = j.getJiraPriority(""+currentPriority);
if(j.verbose == "true"){
JSUtil.logObject(issue);
}
We then pass that object into a script include and the function to create in incident via rest message is below..
var jiraIssue = j.createIssue(issue);
var json = new JSON();
var body = json.encode(issue);
var r = new RESTMessage('Jira Issue', 'post');
r.setBasicAuth(gs.getProperty('com.snc.integration.jira.jira_api_user'), gs.getProperty('com.snc.integration.jira.jira_api_password'));
r.setXMLParameter('issuebody', body);
r.setStringParameter('base_endpoint', gs.getProperty('com.snc.integration.jira.base_jira_instance_url'));
var res = this._submitBodyTypeRequest(r, true);
return res;
Let me know if this helps with your troubles?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2014 07:47 PM
Hey,
I have checked a REST message that uses JSON in my system and here is a snippet, maybe this will help. This posts incidents to Jira..
So we start but running a business rule and create an object...
var issue = new Object();
issue.fields = new Object();
issue.fields.project = new Object();
issue.fields.project.key = gs.getProperty("com.snc.integration.jira.project");
issue.fields.summary = ""+current.short_description;
issue.fields.issuetype = new Object();
issue.fields.customfield_10025 = ""+current.number;
issue.fields.issuetype.name=""+current.subcategory;
issue.fields['customfield_'+j.sysidField] = j.getSysIdPrefix()+":"+current.sys_id;
issue.fields.priority = new Object();
issue.fields.priority.id = j.getJiraPriority(""+currentPriority);
if(j.verbose == "true"){
JSUtil.logObject(issue);
}
We then pass that object into a script include and the function to create in incident via rest message is below..
var jiraIssue = j.createIssue(issue);
var json = new JSON();
var body = json.encode(issue);
var r = new RESTMessage('Jira Issue', 'post');
r.setBasicAuth(gs.getProperty('com.snc.integration.jira.jira_api_user'), gs.getProperty('com.snc.integration.jira.jira_api_password'));
r.setXMLParameter('issuebody', body);
r.setStringParameter('base_endpoint', gs.getProperty('com.snc.integration.jira.base_jira_instance_url'));
var res = this._submitBodyTypeRequest(r, true);
return res;
Let me know if this helps with your troubles?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2014 12:03 PM
Using setXMLParameter to send the JSON instead of setStringParameter did the trick. Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2014 07:56 AM
Thank you for the helpful post MG. Using setXMLParameter solved my issue, and I don't know how else I would have found this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2015 07:44 AM
When using RESTMessageV2, call setStringParameterNoEscape() instead. The method setXMLParameter does'nt seem to work.