- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2022 12:34 PM
Hi
I am making a REST call to an external system and based on what is the value need to create a manual task for a group.
Below is the response back that I get in ServiceNow and I need to create a task only if the "Status" has a value in it (which signals that there is an error )
{"status":null,"requestID":null,"warnings":null,"errors":["Status : failed\.\n"],"retryWait":0,"metaData":null,"attributes":null,"complete":false,"failure":false,"success":false,"retry":false}
How do I read the value of status in my script in workflow?
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2022 08:18 AM
Try
var response = r.execute();
var responseBody = JSON.parse(response.getBody());
gs.log(responseBody.errors);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2022 02:59 PM
set a variable equal to the response such as
var response = {"status":null,"requestID":null,"warnings":null,"errors":["Status : failed\.\n"],"retryWait":0,"metaData":null,"attributes":null,"complete":false,"failure":false,"success":false,"retry":false};
then you can read the errors using response.errors
example
if(response.errors){
//there is an error
gs.log("there is an error");
}
else{
//there isn't an error
gs.log("there isn't an error");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2022 08:10 AM
Thanks so much Mike_R for responding. But I still get undefined when I do the response.errors.
Actually this is what I have
var response = r.execute();
var responseBody = response.getBody();
gs.log(responseBody.errors) -> shows undefined.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2022 08:18 AM
Try
var response = r.execute();
var responseBody = JSON.parse(response.getBody());
gs.log(responseBody.errors);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2022 08:54 AM
Thanks so much. That worked!