- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2022 02:56 AM
Hello,
I have an issue regarding extracting field from a response body, which currently is giving me undefined value in background scripts. Here's how the script and response looks;
var response = request.execute();
var responseBody = response.getBody();
gs.print(responseBody); //This gives me [{"error":"SIM already activated for MSISDN 1122334455667788","ret":-2}]
var parse = JSON.parse(responseBody);
gs.print(parse); //This gives me [object Object]
var errorMessage = parse.error; //Here's where I'm trying to extract 'error' message from responseBody, but doesn't seem to be correct
gs.print(errorMessage); //This gives med undefined
Any clue what I'm doing wrong or where I can improve my script in order to work?
Please let me know if further information is needed.
Best regards,
Adrian
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2022 03:02 AM
Hi,
update as this
var errorMessage = parser[0].error;
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
08-10-2022 03:02 AM
Hi,
update as this
var errorMessage = parser[0].error;
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
08-10-2022 03:29 AM
Awesome, thank you so much
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2022 04:04 AM
Glad to help.
Please mark response helpful as well.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader