Sunday, August 8, 2021

Power Automate: Send Multiple Attachments In EMail

 Hello Friends,

Welcome back with another post on Power Automate. Have you ever face any requirement where all the attachments of any list item needs to send through Email? Let's suppose a user submits a request in system along with multiple attachments. Now the details of this request needs to by sent to his/her manager along with the attachments, he/she has uploaded. How will you do? No Idea, let's try:-

  1. I have created a list "TestList" with only one column i.e. "Title".

  2. Let's create a Power Automate. For this click on App Launcher (9 dots) at top left corner and choose "Power Automate".
  3. Click on "+ Create" >> "Automated cloud flow". It will show a popup window where you need to input the name of the workflow. Then choose the type of trigger upon which this workflow will execute.
  4. Choose "When an item is created (SharePoint)".

  5. Click on "Create".
  6. It will create a blank workflow with a default action "When an item is created". Choose the SiteName and the list name upon which you need to execute this workflow.


  7. Now take a pause. First discuss how we will perform next. First we need to 
    1. Get all attachments list
    2. Get content of each attachment and make an array of the same with File Name and ContentBytes.
    3. Send this array as attachment in Email.
  8. Let's start-
  9. Choose an action Get attachments


  10. Now define a variable of Array type.


  11. Now we will use Apply to each action to get attachment contents and append in array.
  12. For this, first we will add action "Get attachment content" and fill properties as below. The Id field will be mapped with the Item ID (when an item is created) while File Identifier will be mapped with the Id (Get attachments).


  13. The moment you bind File Identifier field, you will see that "Apply to each" action automatically binds with the Get attachment content action.


  14. Now, add one more action "Append to array variable". We will append all attachments in the variable defined earlier.


  15. The format of array is-
    1. {
      "Name":
      "ContentBytes":
      }
      
  16. Now the last part. Add an action "Send an email (V2)". Specify the To, Subject, Body as per the requirement. Once done, click on "Show advanced options".


  17. It will expand the window and will show Cc, Bcc, Attachments options. By default the system provides to give display name and content separately. But as we have the array here, so we will click the toggle icon showing ahead to Attachments section. This toggle icon toggle the attachments linking process between single to array and vice versa.

  18. After toggle, click on box provided for attachments and select the array variable.
  19. That's all. Save the flow and test the same.
  20. To get the same tested, I came back to the SharePoint list and added one list with 4 attachments
    1. .txt file
    2. .docx file
    3. .pdf file
    4. .png file


  21. First, I check the Run history of workflow. I found it ran successfully.

  22. Now, I will check my mail box.
  23. Wow, I had an email in my inbox with the same attachments I had uploaded.


  24. This way, you can, send all the attachments, user has uploaded in system.
  25. With this, we have achieved our goal.
  26. Now, I am giving you a task. Let us suppose, I have to send all these attachments in approval mail "Start and wait for approval", then how would you do that? Try it.
  27. I will, show the same in my next post.
    1. Power Automate: Send Multiple Attachments In Approval EMail
With this, I am concluding this post.
Happy Coding !!!
Will see you again with some new topics.

Stay Safe !
Stay Healthy !

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.