How To Attach Email Attachments To Existing List Item

Introduction

 
In my previous article, we discussed how to collect information from external users and then add this information to SharePoint. This is an extension of the same article. Here, we will discuss how we can collect the documents from the emails received from external users and then attach them to an already existing record in SharePoint.
 
Let us consider the same business use case that we discussed previously, i.e., Collection of personal information from the potential candidate to be considered for an initial round of interview.
 

The Approach

  • In the previous article, we used MS Form to collect the personal information and to push the collected information into a SharePoint list through MS Flow.
  • The collection of the CVs of candidates is the most important step of this whole recruitment process. MS Form currently offers a limited functionality as it is not possible to upload the documents such as candidate's CV in MS Forms.
  • The only way to collect CVs from candidates is through email. So, we will explore how we can collect the CVs through email and then associate this CV to the corresponding record of the candidate. We will achieve this objective by creating one more Flow.

Let us begin with notifying the candidate

  • As a first step, we will extend the flow that we created in the previous article and will add an additional step to send an email notification to the candidate with the message that his/her form was accepted.
  • The message should contain the clear instructions that the candidate should reply to the email received by them and send the CV along with this E-Mail. (Refer to the image below).
How To Attach Email Attachments To Existing List Item
Now, let's expand the Send an Email action and then go through it.
 
How To Attach Email Attachments To Existing List Item
In the image above, please observe the highlighted sections.
  • The Email ID mentioned in the To field is the Email ID provided by the candidates while submitting the personal information through MS Form.
  • The ID is the dynamic content which is picked from the newly created sharepoint list item. Please note that this is a very important link between the candidate and the information stored in the SharePoint.
  • Please note the highlighted text in the body of the email which reads "********** Important Please do not change the subject of this email ****** ". This message is to ensure that a candidate does not change the subject of the email as this subject will be used in the upcoming steps below.
Now, save this Flow and then let us re-iterate the steps we have discussed so far.
  1. HR Recruiters sends a MS Form to the potential candidates and asks them to submit the personal information.
  2. The candidates submit the personal information using the MS form, but they cannot submit the CV due to the limitation of MS Form.
  3. This information flows into the Sharepoint list through the MS Flow and an email is sent back to the candidate in a specific format i.e. 

    How To Attach Email Attachments To Existing List Item

  4. It is important to note that the ID in the subject line is the itemID of the newly created record in the sharepoint list based on the information submitted by candidates through the MS Form.
  5. Let us now create a MS flow which gets triggered when an email is received by HR recruiter and extracts the attachment(s) and then pushes it to the corresponding list item in the sharepoint.

Finally, the steps to attach the CV to the list item using MSFlow

  1. The trigger action to initiate the Flow will be "On new Mail" so that the flow gets initiated after the email is received by the creator of the flow.

    How To Attach Email Attachments To Existing List Item
  2. The next step is to pick the itemID of the record which was created for the candidate, to do so create an action to initialize the variable (ref image below)

    How To Attach Email Attachments To Existing List Item
    • This is the most important step, this is where we will use the expression within MSFlow to extract the ID from the subject line.
    • To extract the list item Id, put the cursor on the Value field and then enter the below expression under expression tab which is populated at the right of the screen.

      How To Attach Email Attachments To Existing List Item
      1. substring(triggerBody()?['Subject'],add(length(triggerBody()?['Subject']),lastIndexOf(':',triggerBody()?['Subject'])),mul(lastIndexOf(triggerBody()?['Subject'],';'),-1))   
    • The expression above is almost like the formula we use in Excel, this expression basically extracts the ID from the subject of the email and then assigns it to the variable itemId. For example, if the ID of the record created for the candidate is 50 then the subject of the email will be "Confirmation of your submission:50" (Refer to the steps above)

  3. The next step is to attach the CV from the email to the corresponding personal information record of the candidate, which is stored in the sharepoint list.

    • Choose the Apply to each action and select the Attachments from the Dynamic content window displayed on the right side of the screen.

      How To Attach Email Attachments To Existing List Item

    • Then Click on the Add an Action button and Choose the sharepoint action to Add attachment

      How To Attach Email Attachments To Existing List Item

    • Then add the information as shown in the image below.

      How To Attach Email Attachments To Existing List Item

    • The Id field will have an expression "int(variables('ItemId'))" so that the string variable ItemId is converted to the Int.
    • Select below options from the dynamic content window,

      • Attachments Name under File Name
      • Attachments Content under File Content

  4. The action block looks like the image below.

    How To Attach Email Attachments To Existing List Item
Now, save the flow and test it.


Similar Articles