- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2022 11:03 PM
Hi Team,
I am getting response in Json then I am converting into string.
As per below image I want to fatch test id and it is giving me result
Same configuration I am doing in scheduled job but there I am not getting result
Can someone help me here?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2022 01:02 AM
Hi,
this should work fine
var response1 = r1.execute();
var responseBody1 = response1.getBody();
var httpStatus1 = response1.getStatusCode();
gs.info("test" + responseBody1);
var parsedData = JSON.parse(responseBody1);
gs.info(" test:" + parsedData.data[0].id);
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
‎01-11-2022 11:09 PM
Hi
please always use only the two following standard methods for converting JSON to String and vice-versa
- JSON.stringify()
- JSON.parse()
Kind regards
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2022 12:50 AM
Hi Maik,
Now I am using like below code-
var response1 = r1.execute();
var responseBody1 = response1.getBody();
var httpStatus1 = response1.getStatusCode();
gs.info("test" + responseBody1);
var str = JSON.stringify(responseBody1);
var parser = new JSONParser();
var parsedData = parser.parse(str);
gs.info(" test:" + parsedData.data[0].id);
But still i am not getting result.
In responseBody1 I am getting response like - {"data":[{"displayName":"TEST","id":117}]}
How can i solve it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2022 01:58 AM
Hi
as I see
Please let us know whether his solution proposal works for you!
Kind regards
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2022 01:02 AM
Hi,
this should work fine
var response1 = r1.execute();
var responseBody1 = response1.getBody();
var httpStatus1 = response1.getStatusCode();
gs.info("test" + responseBody1);
var parsedData = JSON.parse(responseBody1);
gs.info(" test:" + parsedData.data[0].id);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader