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

Community site session details

Session Id :
Power Automate - Building Flows
Answered

Filter an array of attachements from a sharepoint list

(0) ShareShare
ReportReport
Posted on by

Hello, I am trying to filter an array I have created to get the attachments from a SharePoint list.

What I am trying to do is make it so that when information is entered in the SharePoint list the flow will kick off and send the information from the list item in 3 separate emails. I have this working, the next step is to get the attachments and filter them by name to get attached to the emails. There should be two attachments to for each list item, both PDFs, one for Accounting and one for Insurance. The 3rd email is just a general email with some of the information from the list entry.

 

I have tried Filter Array, I cannot get it to return the results that I am looking for, it will still attached both items to the emails instead of the intended one for each email.

 

I followed this thread to get them both to attach to one email. https://flow.microsoft.com/en-us/blog/multiple-attachments-single-email/

 

Any help would be appreciated!

 

I have the same question (0)
  • Verified answer
    fchopo Profile Picture
    8,003 Moderator on at
    Re: Filter an array of attachements from a sharepoint list

    Hello @Anonymous 

    You could use a switch statement, with different paths according to the first 3 letters of the file name, for example. Have a look at this sample:

     

    accounting.png

     

     

    According to the first 3 letters of the attachment's filename, flow goes to Accounting or insurnance branches, using the following expression:

    substring(items()?['Apply_to_each']?['DisplayName'],0,3)

     

    Hope it helps!

    Ferran

  • Community Power Platform Member Profile Picture
    on at
    Re: Filter an array of attachements from a sharepoint list

    @fchopoThank you for the assistance, I am encountering an error though, it says "Template validation failed: the template acction 'Switch' at line '1' and column '2810' is not vaild: "the template languages function 'items' must have at least one parameter.

     

    Also what is in the compose function? I just put in the 'Display Name' from the Get attachment step.

     

     

  • Community Power Platform Member Profile Picture
    on at
    Re: Filter an array of attachements from a sharepoint list

    So i was able to get it to work. For the compose I used the 'DisplayName' from the 'Get Attachments' then for the switch I used

    substring(outputs('Compose'),0,3)

    And it is now working.

     

    The last question I have, is there a way to make it more idiot proof? So that the capitalization of the file name would not matter?

  • Community Power Platform Member Profile Picture
    on at
    Re: Filter an array of attachements from a sharepoint list

    I also was able to solve this issue by using the 'toUpper' command to change the file names to all uppercase then change the switch to all upper case.

  • DudelerDad Profile Picture
    47 on at
    Re: Filter an array of attachements from a sharepoint list

    I used a condition instead of a switch but your solution got me heading in the right direction.

    Thanks.

    Chris

  • Community Power Platform Member Profile Picture
    on at
    Re: Filter an array of attachements from a sharepoint list

    This works great but if there is more than one attachment that matches the output it sends multiple emails. How would I loop each 3 letter filter so it picks up all the attachments with matching criteria so it sends only one per 3 letter switch.

     

    example it would find the 3 rep jpgs and send then in one email then find the NHM jpg and so on 

     

    rep1.jpg

    rep2.jpg 

    rep3.jpg

    NHM.jpg

    Cle.jpg

  • DudelerDad Profile Picture
    47 on at
    Re: Filter an array of attachements from a sharepoint list

    You could create an array variable for each case and then append to the variable as it loops through.

    Then attach each variable to each email. I put this all in a Scope called 'collectattachments'.
    Then I had another Scope that sends all the emails with the variables as the attachment.


    So collect all the attachments in one step and then send the emails in another. Hope this helps.

    DudelerDad_1-1666877191362.png

    DudelerDad_3-1666877720516.png

     

     

    DudelerDad_2-1666877509249.png

     

     

  • Community Power Platform Member Profile Picture
    on at
    Re: Filter an array of attachements from a sharepoint list

    Thanks but i cant seem to get the append to variable to give me a name the box is greyed out.

     

    Have you used initialize variable somewhere else in the flow and what type I tried string and array types but to no joy I either get no attachments or suffer the same multiple emails instead of one with all the relevant attachments.

  • DudelerDad Profile Picture
    47 on at
    Re: Filter an array of attachements from a sharepoint list

    Yes you have to Initialize all your variables before you can use them elsewhere in the flow. You have to do this on the top level which means a lot of time you end up with this huge list of variables at the top of your flow.

    DudelerDad_0-1666958231098.png

    So create (initialize) the variable as an array. You should then be able to use the 'Append to array' action, select the variable and add the DisplayName and ContentBytes from the 'Get attachment content' action.

    DudelerDad_2-1666959209878.png

     

     

     

     

  • Community Power Platform Member Profile Picture
    on at
    Re: Filter an array of attachements from a sharepoint list

    Thanks for clearing that up.

     

    I had to change the append slightly for the ContentBytes from Body to AttachmentContent. All I was getting was the file name in the attachment section where as now I get the actual attachment now.

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

Coming soon: forum hierarchy changes

In our never-ending quest to improve we are simplifying the forum hierarchy…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Automate

#1
Tomac Profile Picture

Tomac 544 Moderator

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 482 Super User 2025 Season 2

#3
chiaraalina Profile Picture

chiaraalina 287

Last 30 days Overall leaderboard