- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2025 02:54 AM - edited ‎05-19-2025 02:56 AM
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
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2025 04:54 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2025 10:49 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2025 04:10 AM
Use below code for 1. create a new sc task when task id with state = Error.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2025 04:29 AM
Note - How to loop through object in sub flow ? I am using flow designer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2025 04:39 AM - edited ‎05-19-2025 04:41 AM
you can use JSON parser step in flow
check these videos
Episode 25 - Complex Objects in ServiceNow Flow Designer
How To - Use the integrationHub JSON Parser - Paris Release
also check these links
Script for JSON Parse Action in Flow Designer
Flow/subflow array.object value extraction
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2025 04:42 AM
I have object from action received into a subflow. Lets says the object is below. I have to loop through the "Tasks" below in my sub flow and reach each task id and state and based on the state, want to create sc task or update ritm.
{
"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"
}