PortiBlog

Let MS Flow take over your manual actions

22 mei 2019

Save attachments with metadata from file name

Think about that specific process of different daily reports or the registration of certificates which are all send by email and stored in places where you can’t find them again.

In all cases, there are a lot of manual steps that need to be taken by a person who is responsible for the process of handling the reports.

With Microsoft Flow (and strict formatting of the attachment name) not a single person would need to intervene in the process of storing the attachments in the correct place or edit them to add the correct metadata.

One: MS Flow will check an Outlook address (possibly with specific rules or folders) for new messages with attachments and store them on a specified SharePoint location.

Two: MS Flow will take the document name (we are now in a SharePoint Library, hence document) and cuts it into little pieces of text to be put in an array. From this comes the information to be set in the relevant metadata fields.

The incoming email is “Trigger one” and creating the document in the SharePoint library is “Trigger two”.

This raises the question: “Why two triggers?”

Answer: At the moment, it is not possible to set metadata fields of an incoming email and saving the attachment to SharePoint through MS Flow.

However, this MS Flow creates a new document on SharePoint. So we can create an additional MS Flow with the required logic.

Conclusion: We have two triggers for two Microsoft Flows.

Now you have an understanding of the functional steps to take, but how is this set-up in real life MS Flow?

The first trigger

Let’s review the first trigger: You can use the template “Save my email attachments to a SharePoint document library” and use the required credentials for the incoming emails in Outlook and in SharePoint to store the attachment.

Of course you can make it more extensive if you need, but in this case the attachment naming formatting is already in place and “everybody” knows about it.

 

 

The second trigger

The second trigger is the creation of a new document based on the first MS Flow.

The document name in my case will be separated by an underscore “_”. So the document name will look like: “Daily Report_Vessel attendance_Argonaut.pdf” corresponding with “Title”, ”Type of Document” and ”Choice”.

  1. We start from a blank template with the trigger “When a file is created (properties only)”.

Select your site and your Library

  1. Then we need to get the document so we will know where to write back the separated values.

Select your site and your library one again and use ID from SharePoint as Key.

  1. Now we are going to set the variables (see table: Variables for specifics or screen cap: Variables from MS Flow). When creating the variables, use the action “Initialize variable”. We are creating and setting them at the same time.

Take note! Variables below are set based on three values which we would like to write back to SharePoint, less or more variables are possible by adding a number to the variables and Array location.

Name Type Value
FileName String SharePoint field: Name
SplitArray Array Expression: split(variables('FileName'),'_') ß underscore separator
SplitValue0 String Expression: variables('SplitArray')[0]
SplitValue1 String Expression: variables('SplitArray')[1]
SplitValue2 String Expression: variables('SplitArray')[2]

Now we have all values to use the action “Update file properties”. Select the variables in the place where you want to fill the metadata.*Table: Variables

* Screen cap: Variables from MS Flow
* SplitValue1 and SplitValue2 are the same but with corresponding numbers for Array position

  1. Now we have all values to use the action “Update file properties”. Select the variables in the place where you want to fill the metadata.
  2. Last step, save your creation and let MS Flow take over your manual actions.

If you don’t need extra steps or confirmation emails then your Flow can be very small for a large amount work.

Inspired? Watch more Flow articles from my co-workers for more useful items on Microsoft Flow.

Good luck and have fun building!

Submit a comment