Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - Using Flows
Answered

Apply_to_each failing

(0) ShareShare
ReportReport
Posted on by 8

This error just started 3 days ago after running successfully for 3 months. This is the error MS gives:

 

The execution of template action 'Apply_to_each' failed: the result of the evaluation of 'foreach' expression '@items('Apply_to_each_2')?['{Identifier}']' is of type 'String'. The result must be a valid array.

 

The flow checks the age of files in a SharePoint and deletes those over 180 days old - the error seems to be pointing at the Identifier value in the nested loop:

ColbyBoone_1-1691510545883.png

 

I'm not sure why the error has started since the backend SharePoint files haven't changed nor have I touched this Flow since March. 

 

  • ColbyBoone Profile Picture
    8 on at
    Re: Apply_to_each failing

    Testing that change succeeded - I remember setting this up and not wanting the nested loop but Automate kept creating it when I selected Delete File as an action. It was odd but I'd never made a flow before so I thought it might be required.

     

    Thank you!

  • Verified answer
    wskinnermctc Profile Picture
    6,517 Super User 2025 Season 1 on at
    Re: Apply_to_each failing

    After looking at your flow again, I don't know how it could be working in the first place.

     

    The first apply to each "Apply to each 2" is based on a SharePoint get files step. So for each file it will do actions within "Apply to each 2".

     

    The second apply to each "Apply to each" is trying to say, "For each individual file in Apply to each 2, I would like to get each Identifier for that individual file. The do actions to each one of those identifiers."

     

    That doesn't make sense. Each file only has 1 identifier, it doesn't have a list of identifiers.

     

    I made an example and mine failed because it can't apply to each on an identifer.

    Example Apply to EachExample Apply to EachExample Apply to Each FailedExample Apply to Each Failed

     

     

    So I don't know how this flow was working at all for months. It doesn't work once. I can only guess it never had any files that were 180 days old, so it never got any further than the first "Apply to each 2" because it was always empty. So the second "Apply to each" never got a chance to run and create an error.

     

    You should get rid of that nested apply to each and you only need one.

     

    Delete a FileDelete a File

     

    This example should work correctly. Let me know if this works for you.

  • ColbyBoone Profile Picture
    8 on at
    Re: Apply_to_each failing

    All the files are labelled "YYYY-MM-DDT##_##_##+##_##-REPORTNAME" where the # are integers and I have no idea why there is a letter T after the date. The file names are all the same except for the data and however the #'s are assigned from our ERP that spits these out; e.g.: "2023-02-06T23_45_39+00_00-Primary Ledger Trial Balance YTD". 

     

    The file name format hasn't changed since I set this flow up either, so I hope that it isn't the problem. 

  • wskinnermctc Profile Picture
    6,517 Super User 2025 Season 1 on at
    Re: Apply_to_each failing

    Are there any files or folders with special characters that you know of? Like @ % & * ' " { ]

     

    I'm only guessing to troubleshoot. Sometimes special characters throw off the power automate code as it is transmitted. I don't know what it could be but maybe something to check for.

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,635 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,997 Most Valuable Professional

Leaderboard

Featured topics

Restore a deleted flow