- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2016 11:51 PM
Hello,
This is a part of my JSON message which accepts array input
{
"value": {"array": { "elements": [
{"number": {"value": 80}},
{"number": { "value": 100 }}
]}
},
"type": "Array/number",
"name": "cdmAddDisk",
"scope": "local"
}
The value I have to pass here comes from a Request Item multi line text separated by commas.
But it does not accept it. Any idea?
Thanks,
Vinitha.K
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2016 03:00 AM
I got it by setting r.setStringParameterNoEscape();
r.setStringParameterNoEscape("cdmAddDisk",global.JSON.stringify(str.split(',')).replace(']',',]').replace(/\"/g,"{\"number\": {\"value\":").replace(/{\"number\": {\"value\":,/g,"}},").replace(',]',']'));
Thank you so much for the help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2016 01:13 AM
You can change the above code in below way to get the ouptput in your format...try below in backgroup scritp and see the output.
var str = '80,100';
gs.print(global.JSON.stringify(str.split(',')).replace(']',',]').replace(/\"/g,"{\"number\": {\"value\":").replace(/{\"number\": {\"value\":,/g,"}},").replace(',]',']'));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2016 01:58 AM
r.setStringParameter("cdmAddDisk",global.JSON.stringify(str.split(',')).replace(']',',]').replace(/\"/g,"{\"number\": {\"value\":").replace(/{\"number\": {\"value\":,/g,"}},").replace(',]',']'));
If I set in the script like this, I get the same 400 error again.
https://virtualviking.net/2015/06/15/using-servicenow-as-a-front-end-for-vrealize-automation/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2016 02:05 AM
Can u pls share you script and the complete error message ur getting..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2016 02:14 AM
I am getting the values through request item variables and passing it to JSON message(I have already shared).
script to pass the RITM variables to POST script,
r.setStringParameter("cdmBusinessJustification", current.variables.BusinessJustification);
r.setStringParameter("cdmAddDisk",global.JSON.stringify(str.split(',')).replace(']',',]').replace(/\"/g,"{\"number\": {\"value\":").replace(/{\"number\": {\"value\":,/g,"}},").replace(',]',']'));
r.setStringParameter("cdmPowerStartTime", current.variables.PowerStartTime);
r.setStringParameter("cdmPowerStopTime",current.variables.PowerStopTime);
r.setStringParameter("cdmPowerWeekends", current.variables.PowerWeekends);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2016 02:26 AM
Ok got it.... so the json string building here is getting replace with your REST post content variable "cdmAddDisk". I suspect issue is with that binding (one small char in between can make this a bad request 400 error). Can u get the output from background script and hardcore the same along with hard coded values for other fields, validate that content with any online json validator site and test from the rest post.....see if you are getting the same error.