
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2020 12:02 PM
I have created two custom actions, one that gets a Token from our AD and one that adds users to a specific group using that token. The call returns a status of 0 if it fails or 1 if success. I want an if condition so if it fails I can be alerted.
The above flow does not work. I added the pills with the values I want to the log and it looks like my script to parse the JSON is not working because no values are being returned. I know I am parsing the JSON correct when I get the token because I am able to pass it to the next action.
Here you can see no values returned.
Here you can see the call was successful.
This is my action with the script I am using to parse the JSON.
(function execute(inputs, outputs) {
// Only parse the response body if the status code is 200
if (inputs.status_code == '200'){
// Parse the response_body input variable and save parsed object as responseBody
var responseBody = JSON.parse(inputs.response_body);
// Map the parsed responseBody values to output variables
outputs.samaccountname = responseBody.sAMAccountName;
//outputs.objectsid = responseBody.objectSID;
outputs.userprincipalname = responseBody.userPrincipalName;
outputs.statusmessage = responseBody.statusMessage;
outputs.status = responseBody.status;
}
})(inputs, outputs);
Solved! Go to Solution.
- Labels:
-
flow designer

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2020 12:29 PM
Hi Chris,
From the attached screenshots it looks like your response body is an stringified array with a single object. If so can you try the following to parse the response:
(function execute(inputs, outputs) {
// Only parse the response body if the status code is 200
if (inputs.status_code == '200'){
// Parse the response_body input variable and save parsed object as responseBody
var responseBody = JSON.parse(inputs.response_body);
// Map the parsed responseBody values to output variables
outputs.samaccountname = responseBody[0].sAMAccountName;
//outputs.objectsid = responseBody[0].objectSID;
outputs.userprincipalname = responseBody[0].userPrincipalName;
outputs.statusmessage = responseBody[0].statusMessage;
outputs.status = responseBody[0].status;
}
})(inputs, outputs);
--David

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2020 12:24 PM
HI,
Are you sure you get responseBody.status as 0 or 1?
Can you check the real time log? What is the value associated with Status?
Thanks,
Ashutosh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2020 12:30 PM
In the third photo you can see the status response is 1, if I pass a bad username or bad group I get a 0 back for status.
The problem is definitely parsing the JSON response and assigning the values to my outputs.
Here is the output data from a working call and parse.
Here is the one not working

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2020 12:29 PM
Hi Chris,
From the attached screenshots it looks like your response body is an stringified array with a single object. If so can you try the following to parse the response:
(function execute(inputs, outputs) {
// Only parse the response body if the status code is 200
if (inputs.status_code == '200'){
// Parse the response_body input variable and save parsed object as responseBody
var responseBody = JSON.parse(inputs.response_body);
// Map the parsed responseBody values to output variables
outputs.samaccountname = responseBody[0].sAMAccountName;
//outputs.objectsid = responseBody[0].objectSID;
outputs.userprincipalname = responseBody[0].userPrincipalName;
outputs.statusmessage = responseBody[0].statusMessage;
outputs.status = responseBody[0].status;
}
})(inputs, outputs);
--David