Iterating over Array.Object
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-03-2022 02:05 PM
I'm having issue with Process Automation using a 'for' loop to access items in an object array. My output object looks as below and varies in number of objects returned each time the data is fetched:
{
"resultArray": [
{
"device_model": "TestString",
"city": "Test City",
"ip": "8.8.8.8",
"device_type": "web",
"geo": "US",
"protocol": "tcp",
"hostname": "test.hostname.com",
"port": "443",
"tag": "web",
"device_vendor": "Test Vendor",
"region": "Test Country",
"asn": "1234",
"timestamp": "2022-01-31 07:13:28"
},
{
"device_model": "TestString",
"city": "Test City",
"ip": "8.8.8.8",
"device_type": "web",
"geo": "US",
"protocol": "tcp",
"hostname": "test.hostname.com",
"port": "443",
"tag": "web",
"device_vendor": "Test Vendor",
"region": "STATE",
"asn": "1234",
"timestamp": "2022-01-31 08:33:54"
}
]
}
When I utilize a 'for each item in resultArray' I am returned an empty object, rather than each object in the array that I would like to further automate over. I believe its the manner in which I'm outputting the script data, but have tried a number of iterations with no success. My settings in the script and flow are as below:
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2022 08:35 PM
In the script, JSON.stringify() will convert the json object into a String. So "output" should be a String instead of an Array.Object.
If setting variable "output" as a Array.Object, just don't stringify the resultArray.
outputs.output = resultArray;