web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Apply to each failing ...
Power Automate
Unanswered

Apply to each failing as the result must be an array

(0) ShareShare
ReportReport
Posted on by 31
Hi All,
 
I've got a flow I'm working on that looks at two Sharepoint lists, one has a list of all the Team Members in the department and another that has a list of submissions in a month.  The flow checks who in the Team hasn't made a submission in the month and sends a list of names to the Manager due to some people not being on email.
 
The flow gathers a list of the team, a list of the submissions and a list of Managers correctly but the raw input is showing them as being in object form rather than array. { "body": [ { }... 
 
My Apply to each loop is failing with the following error: 
 
Action 'Apply_to_each' failed: The execution of template action 'Apply_to_each' failed: the result of the evaluation of 'foreach' expression '@outputs('DistinctManagers')' is of type 'Object'. The result must be a valid array.
 
Everything else appears to be working OK but I can't get around this error, can anybody assist please?
Flow overview.png
Categories:
I have the same question (0)
  • Kalathiya Profile Picture
    2,456 Super User 2026 Season 1 on at
    Hello @KB6

    DistinctManagers should be returning an array, but at the moment it’s coming through as an object, which is causing the Apply to each to fail. 

    Could you please let me know what expression you’re using inside the DistinctManagers Compose action?

    It would really help to see exactly what that step is doing, as that’s likely where the array is being wrapped into an object. Once we can see the expression, it should be easier to identify what’s causing the issue.

    If this response resolves your issue, please mark it as the Verified Answer so it can help other community members as well.
    ---------------------------------------------------------------------------------
     
    📩 Need more help? Mention @Kalathiya anytime!
    ✔️ Don’t forget to Accept as Solution if this guidance worked for you.
    💛 Your Like motivates me to keep helping!
  • KB6 Profile Picture
    31 on at
    Hi Kalathiya,
     
    Thanks for replying, this is what I have got:
     
    Select Submitted Names
    From: outputs('GetSubmissions')?['body/value']
    Map: FullName 
    Value: 
    if(
      and(not(empty(item()?['Surname'])), not(empty(item()?['FirstName']))),
      concat(item()?['Surname'], ' ', item()?['FirstName']),
      if(
        not(empty(item()?['Name']?['DisplayName'])),
        if(
          contains(item()?['Name']?['DisplayName'], ','),
                concat(
             trim(first(split(item()?['Name']?['DisplayName'], ','))),
             ' ',
             trim(last(split(item()?['Name']?['DisplayName'], ',')))
          ),
                concat(
             last(split(item()?['Name']?['DisplayName'], ' ')),
             ' ',
             first(split(item()?['Name']?['DisplayName'], ' '))
          )
        ),
        ''
      )
    )
     
    Select Employees
    From: outputs('GetTeamMembers')?['body/value']
    Map: FullName
    Value: item()?['field_1']
    Map: ManagerEmail 
    Value: item()?['Manager']?['Email']
     
    Filter NoSubmission
    From: body('Select_Employees')
    Filter Query: 
    not(
      contains(
        toLower(string(outputs('Select_SubmittedNames'))),
        toLower(concat('"FullName":"', item()?['FullName'], '"'))
      )
    )
     
    Filter ValidManagers
    From: body('Filter_NoSubmission')
    Filter query: 
    and(
      not(empty(item()?['ManagerEmail'])),
      contains(item()?['ManagerEmail'], '@')
    )
     
    Select ManagerEmails
    From: body('Filter_ValidManagers')
    Map: Email
    Value: item()?['ManagerEmail']
     
    DistinctManagers
    Inputs: 
    union(outputs('Select_ManagerEmails'), outputs('Select_ManagerEmails'))
     
    Apply to each
    outputs('DistinctManagers')
     
    Filter EmployeesForManager
    From: body('Filter_ValidManagers')
    Filter Query: 
    equals(
      toLower(item()?['ManagerEmail']),
      toLower(items('Apply_to_each'))
    )
     
    Select 2
    From: body('Filter_EmployeesForManager')
    Map: Name
    Value: item()?['FullName']
  • Kalathiya Profile Picture
    2,456 Super User 2026 Season 1 on at
    @KB6
     
    Thanks for sharing the full flow that helps a lot. 
     
    outputs('DistinctManagers') is of type Object. The result must be a valid array.. So your Apply to each is trying to loop over something that isn’t an array.
     
    Your issue is here that you using output instead of body in DistinctManagers compose action:
    your current code:
    union(outputs('Select_ManagerEmails'), outputs('Select_ManagerEmails'))

    outputs() returns the whole action object, not the array so Apply to each receives an object instead of an array.

    Change DistinctManagers to:

    union(body('Select_ManagerEmails'),body('Select_ManagerEmails'))
    Hope this helps!
     
    If this response resolves your issue, please mark it as the Verified Answer so it can help other community members as well.
    ---------------------------------------------------------------------------------
     
    📩 Need more help? Mention @Kalathiya anytime!
    ✔️ Don’t forget to Accept as Solution if this guidance worked for you.
    💛 Your Like motivates me to keep helping!
     
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Valantis Profile Picture

Valantis 377

#2
11manish Profile Picture

11manish 279

#3
David_MA Profile Picture

David_MA 234 Super User 2026 Season 1

Last 30 days Overall leaderboard