How to parse JSON object values in Business rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2022 04:11 AM
Hi,
I am having following response which I need to parse and get the text in the 'value' key shown below . Please suggest .
I have tried parse2.field47191.value but it is not working . Getting error as 'com.glide.script.RhinoEcmaError: Cannot read property "value" from undefined'
I have tried this.
var parse2 = JSON.parse(responseBody);
var wvalue = parse2.field12332.value
{
"field12332":
{
"profile":"xyzrt",
"id":6,
"value":"NY-tester-704-HXQ-NY211"
},
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2022 04:21 AM
can you add gs.addInfoMessage() or gs.log() to see whats coming in parse2 and parse2.field12332.value
also try to add parse2.field12332.value.toString()
sometimes it works.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2022 04:21 AM
Hi,
I used this json and it worked well
there should not be a comma after this
{
"field12332": {
"profile": "xyzrt",
"id": 6,
"value": "NY-tester-704-HXQ-NY211"
}
}
var json = '{"field12332":{"profile":"xyzrt","id":6,"value":"NY-tester-704-HXQ-NY211"}}';
var parser = JSON.parse(json);
var value = parser.field12332.value;
gs.info(value);
Output:
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2022 04:28 AM
Please suggest how to get from here.
{
"firstname":"Max",
"phones":[
{
"phonetype":{
"id":"D83004",
"formattedvalue":"Home",
"value":"Home"
},
"entry":118,
"phonenumber":"+1 720 435-0088",
"primary":true
}
],
"links":[{"rel":"self","title":"The current profile being viewed.","url":"https://api.test.com"}],
"field12332":{
"profile": "xyzrt",
"id":6,
"value":"NY-tester-704-HXQ-NY211"
},
"startdate":"2022-05-25",
"email":"testcand0881@tester.com",
"lastname":"Testmax"
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2022 05:20 AM
it would still work
Is that not working fine?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader