How do I extract the data from a JSON Object in Flow Designer?

gjz
Mega Sage

I have a business requirement to find all groups a specific user is a member of in Active Directory and write the groups to the work notes on a record.  There isn't an OOB action to do this for a specific user so I created my own.  The action is working, but I can't figure out how to extract the data so I can write it to the record in Flow Designer.

 

The action returns the groups in a JSON object, but when I try to use the "For Each" flow logic , it doesn't allow me to select the output from the previous step.

 

Here is my action's output:

 

gjz_2-1748467838240.png

 

This is the flow I'm using to test my action and output - as you can see, I can't select the Groups from the previous step.

gjz_4-1748468191456.png

This is what the "Groups" output looks like from the 2nd step:

gjz_5-1748468494694.png

 

 

 

 

 

 

 

 
 
1 ACCEPTED SOLUTION

@gjz 

I attached gif now here.

you are storing json string in the script step output, but it should be object

if the input to script step is json object then don't use JSON.stringify()

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

18 REPLIES 18

I love the video and think it will help - but it moves too fast and I can't stop it.  Do you know how I can do that?

 

It's still not working, I'm getting the error "Unable to create serializable iterator for items:" with the For Each loop.

 

I added a script step to my custom action that takes the JSON object output that is created in the previous step as input to the script step.  The one difference is you have a string as input, this one is JSON.

 

This is what I ended up with after following your video:

gjz_0-1748541248004.pnggjz_1-1748541279886.png

 

And my Outputs are:

gjz_2-1748541358836.png

 

My test flow is:

gjz_3-1748541466511.png

and the error from the test flow:

gjz_4-1748541572623.png

 

I'm really at a loss on this, what am I missing?

 

@gjz 

I attached gif now here.

you are storing json string in the script step output, but it should be object

if the input to script step is json object then don't use JSON.stringify()

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur - I can't tell you how much I appreciate your help.  I'm still getting the "Unable to create serializable iterator for items" error.  I've watched your video several times and tried some changes, but I must be missing something.  Since I'm not allowed to record anything, I have to do this the hard way.

 

My script step: 

gjz_0-1748616926544.png

and the output for the script step:

gjz_1-1748616964276.png

When I test the action alone, this is what I see:

gjz_2-1748617099428.png

For step 2 - which is the PowerShell step, this is the output.  As you can see, it appears the Output is a string.  Output is the input to the script step.

gjz_3-1748617234024.png

And for the script step:

gjz_5-1748617364711.png

 

I thought I followed your video exactly, do you have any idea what is wrong?

 

Here, try this:

In your script step, change "var parsedData = jsonobj;" to "var parsedData - jsonobj.body;"

 

var jsonobj = JSON.parse(inputs.response_json_object);
var parsedData = jsonobj.body; // Add body to this line
outputs.response_json_array = parsedData;

 

Then update your output variables to remove the body and status strings, and add a single string variable called name like you had previously. Outputs should be:

  • response_json_array (Array.Object)
    • response_json_array_child0 (Object)
      • name (String)

You Action Outputs should match this as well.

 

Some explanation:

 

Your JSON output has two top level keys: Body and Status. You can't iterate through this as the Flow is expecting an array of objects, but this is not an array. However, Body's value is an array of objects, and each of these objects contains a key called "name" which has a string value. Since Body contains the data you are after, we can pass that as the output instead, hence jsonobj.body instead of jsonobj.

Try messing around with this in a background script a little. I often do this if I'm trying to wrap my head around the data structure of an object.

Hope this helps!