How to loop through object in sub flow ? (The object is returned by an ACTION in flow designer)

Snehal13
Kilo Sage

My action makes an API call and this API returns the below response body

{
    "requestDetails": {
        "comments": "mycomments",
        "requestParams": [
            {
                "requestkey": "342",
                "Start Date": "2025-05-15 12:44:25",
                "Request Type": "AddRequest",
                "value": "asasasasa01G3PCBKB170TEP3CC2BBH",
                "status": "Request Created"
            }
        ],
        "Tasks": [
            {
                
                "Task ID": 999,
                "State": "New",
                "comments": " test comments"
            },
           {    
                "Task ID": 29,
                "State": "Error",
                "comments": " test 123comments"
            }  // these tasks could be multiple each with a diff ID and State

        ],
    },
    "msg": "SUCCESS",
    "errorCode": "0"
}

The "Tasks" can be multiple or single. It depends on the API. 

The action returns couple of values back to the subflow - errorCode, entire 'Tasks' object.

 

When errorCode is 0, I want to loop through the Tasks object in my subflow to do the following. The conditional check for validating errorCode is already in place. not getting how to iterate through the object in subflow to achieve -

1. create a new sc task when task id with state = Error.

1. update main ritm to complete when all task id with state = Completed.

 

How to loop through object in sub flow ? I am using flow designer

 

2 ACCEPTED SOLUTIONS

OlaN
Giga Sage
Giga Sage

Hi,

If you define the output from the action as an object containing an array you should be able to loop through the array, just as you would when performing a lookup of records.

See attached image.

loop-through-array.png

View solution in original post

If you don't know which one of them contains data, you'll need to loop through all three arrays.

Or, if possible, have the output of the action concatinate all the data into one big array, and loop through that instead.

View solution in original post

9 REPLIES 9

@Snehal13 

I already shared the videos and it will help you to use Integration Hub parser step

Did you check that?

Also what's your flow action returning?

If it's returning an object, did you try to use For Each to iterate

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

The object is as below

{

"New": [],

"Open": [],

"Closed": []

}

 

Each element may or may not have array elements. Example : New may have 3 values and Closed may be empty and Open may have 1 array value 

 

I want to find which one has values and loop through them dynamically in my subflow

OlaN
Giga Sage
Giga Sage

Hi,

If you define the output from the action as an object containing an array you should be able to loop through the array, just as you would when performing a lookup of records.

See attached image.

loop-through-array.png

The object is as below

{

"New": [],

"Open": [],

"Closed": []

}

 

Each element may or may not have array elements. Example : New may have 3 values and Closed may be empty and Open may have 1 array value 

 

I want to find which one (New/Open/Closed) has values and loop through them in my subflow

If you don't know which one of them contains data, you'll need to loop through all three arrays.

Or, if possible, have the output of the action concatinate all the data into one big array, and loop through that instead.