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

Ankur Bawiskar
Tera Patron
Tera Patron

@gjz 

your action should store that JSON string as Array of object in output variable

Then you can use "For Each" to iterate that array of objects

check this link

Flow - Custom Action returns Array.object but For Each loop shows 0 of 0 

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

Ugh, it still doesn't work.  I'm getting the error "Unable to create serializable iterator for items" on the For Each step. My suspicion is the code in the Post Processing & Handling step needs to be modified to make it an array, I just don't know how to do that.

 

Also, it's possible I didn't create the output correctly - I've not used an array as output before. 

gjz_0-1748535039812.png

 

Ankur Bawiskar
Tera Patron
Tera Patron

@gjz 

check below links

Script for JSON Parse Action in Flow Designer 

JSON Parser step - Flow Designer 

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

I have seen those posts - and many more and have tried several of the solutions without success.

 

My action looks like this:

gjz_0-1748535745102.png

The PowerShell step returns data in the responseBody that looks like this:

gjz_1-1748535942709.png

 

The Post Processing & Handling has script that manipulates the responseBody - I really don't understand what it is doing, I swiped it from an OOB Active Directory action that returns the same type of data.  In the OOB action, the response output is defined as JSON, not Array.Object.

 

gjz_2-1748536243408.pnggjz_3-1748536292007.png

 

So, how do I change that to an Array.Object?

 

 

Ankur Bawiskar
Tera Patron
Tera Patron

@gjz 

here is the working solution, please see and enhance for your case

I believe I have answered your question with working solution.

flow action iterate array of objects in subflow.gif

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