Flow Designer For Each loop using GlideAggregate issues

Erik Gunther2
Kilo Guru

I built a workflow using Flow Designer. I ran into an issue when I implemented a For Each loop on an object returned by a Script Action. The For Each iterates through the list of records, but I cannot pull any field values from any of the records in the loop. Does For Each only work with GlideRecord? I know GlideAggregate extends GlideRecord, so I'm not sure why this wouldn't work.

This first screenshot shows the version against a GlideAggregate object. Note the "Activity Designs" output data shows "View All", which is circled in red. The second screenshot shows the version against the GlideRecord object. Its "Activity Designs" output data lists the Sys Ids of each returned record.

The second issue is with the "If" statement. The first "Condition" value I believe should show the "Order" field value. I circled the blank value in red. Compare this to the second screenshot to see that the GlideRecord does return a value. 

If anyone has had success with using a GlideAggregate in a For Each block, please let me know. I'm hoping this is my error and not a limitation of the platform.

For Each on GlideAggregate:

find_real_file.png

For Each on GlideRecord:

find_real_file.png

5 REPLIES 5

Balaji Jagannat
Kilo Guru

Hi Erik -

As mentioned in the servicenow docs, the GlideAggregate is expected to return a single value or count of records (based on the aggregate function that you use). I don't think you can loop on the result similar to GlideRecord which will hold the details of each result record. 

 

**Mark this response as Correct Answer/Helpful, if this has helped you. 

I'm pretty sure you can based on the Group By value. I was grouping on "Order", and I'm pretty sure I could loop through the distinct Order values. I believe I tested this. Also, if you look at my screenshot of the For Each above, you can see that it has multiple records to iterate through.

SatheeshKumar
Kilo Sage

I think you are using  invalid datatype in your action output variable.  For the output variables you need use Array.String  if you are returning array of strings in your output variable.

find_real_file.png

 

 

applying the above change may fix your issue.

 

 

 

I don't think returning an array of strings will work because the For Each in Flow Designer only works against GlideRecord.