How to pass Json objects in Rest Post method without quotes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2017 05:38 AM
Hi,
I have a requirement where whenever a record is created in a particular table (eg incident), i should pass the ticket number and other fields in key value pair as json objects like below in rest.
{
"incidentid": "INC00101",
"properties": [
{
"code": "summary",
"value": "test incident"
},
{
"code":"description",
"value":"test desc"
},
]
}
I have configured the Rest Outbound and the outbound requires only two parameters "incidentid" and "properties".
here Properties should push all the filled field names and values. i have written a BR on this table to call the rest outbound and trying to pass summary and application name in key value pair
var property=[];
var json = new JSON();
var r = new sn_ws.RESTMessageV2(incidentRestMessage, 'post');
r.setStringParameter('incidentid', current.number);
//summary
if(current.short_description)
{
var summary={"code":"Summary","value":current.short_description.toString()};
property.push(summary);
}
r.setStringParameterNoEscape('properties',JSON.stringify(property));
var response = r.execute();
var responseBody = response.getBody();
var rBody = r.getRequestBody();
gs.log("rest call for "+current.number +" "+rBody);
The log returns as {"incidentid": "INC00105","properties":"[{"code":"Summary","value":"heloo"}]"}. But my end tool doesnot accept the quote between properties string and values.
the highlighted quotes should not be sent when passing the parameters. It shoul dbe like {"incidentid": "INC00105","properties":[{"code":"Summary","value":"heloo"}]"}. When i log only JSON.stringfy(property) it returns without quotes but when i render with setStringParameterNoEscape it adds the quotes. Kindly help me on this.
Thanks,
Divya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2022 11:42 AM
Hi I know this is an old post but just for anyone who comes across it I have found the below article to help solve this issue
https://community.servicenow.com/community?id=community_question&sys_id=d4b732fc1bf910d07a5933f2cd4bcbee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2024 12:42 PM
what was your solution for this ??
