Hi everyone. One of the many great things about being a Flow Community Contributor and having a love for building Flows, is that there are countless opportunities to create Flows for others. In this blog post, I will take you through a real word example where our community member js4 had asked for guidance on how to create planner tasks from email. This request came in three tranches. You can find js4’s post here.
It then became apparent after searching our forum, others were requesting extra functionality from Planner and Flow also. Please see the following link.
Planner attach document from Outlook email
With 94 up votes and posts as recent as January 24th 2019, I thought I’d give this a go as I could see it’s feasibility, despite no template or process for it as of yet.
So here is some information on the Flow before I step you through each action and how to create this for yourself. This Flow will still be create the task when there are no attachments.
Note: Where I have used expressions, or even if there may be potential questions asked around what action provided the value for the dynamic content, I will feature these directly below each image in order. There will be times when the comments section of the action holds this data too.
Prerequisites: The use of a SharePoint Document Library is required. From Documents(Shared Documents), I have added a folder called “PlannerDocs”. You may want to create this for consistency and to make it easier to follow along.
The Flow will be triggered by an email, and in this example here is the email I am using to get it all going.
And a sneak peak at what is created.
Overview of the completed Flow.
“Scope If Email Has Attachments Save to SharePoint”
“Scope If Email Has Attachments Create Sharing Link”
The above Flow has a few key tasks that all culminate in creating the Planner task that contains the body text, the assignee’s, the start date, the due date and the attached resources, if they exist. The following bullet-ed list will help you see where we are going with this.
● Trigger on sent email
● Create a Planner task with assignee’s
● If the email has attachments, save them to SharePoint, if not update the task and description
● If the email has attachments, get them from SharePoint and update the task with resource(s) and the description
We handle this in this way as the native action “Create a task” does not have the functionality to attach resources(at this time). This is why a task is created then updated as you will see as we move through the Flow. So, let’s start with the trigger.
The task creation
Note: The use of the “Start Date Time” and “Due Date Time” have been created for 1 week from today(3rd March 2019 at the time of writing) in line with the title of the email “Create Report For Finance By 1 Week Today”. These can be changed to suit and enhancements could be made to how you want to format and capture these parameters. Further enhancements to these dates and times are outwith the scope of this post.
Now we get the received email using “Get email”.
Note: I have used “Get email” to get the attachments and the email data where some may prefer to enable attachments on the trigger. I prefer to handle my Flows in this way, triggering it and then retrieving the data after, as generally speaking I find it better practice across the majority of connectors and it works better for me.
The body of the email has HTML tags in it, so what better way to strip that out than to use the “HTML to text” action.
To allow us to create a unique folder path on creation and storing of any attachments, we capture the current time(and date).
We then initialise a variable, more on why we have these steps later.
Time for our first Scope. When you have multiple Scopes they work sequentially. So create the scope and name it as below.
Your first “Apply to each” named as the default in this instance.
Time for a little bit of logic as we bring in the first use of a Condition.
There are more than one way that conditions can now be created with the relatively new condition builder. I like to step into the WDL were possible but for further information on this approach please see: So Where has “Edit in advanced mode” Gone on Condition Actions.
With our Condition action, I will firstly cover the Yes branch. Create a Compose action and call it “Compose Sub Folder”. This is the only time you will see the use of variables(‘TimeStamp’) that we set initially.
concat(variables(‘TimeStamp’), ‘-‘ , body(‘Get_Email’)?[‘Subject’])
If the condition returns true, this will mean there are attachments in the email so we will want to save them. A “Create file” action is used and in this example it has been named “Create File In SharePoint PlannerDocs Folder”.
The No branch has no purpose in this Scope, or Flow so it can remain empty.
Swiftly on to our next Scope connector called “Scope If Email Has Attachments Create Sharing Link”.
For the Yes branch, it’s time for the use of our second Condition although it is the same as the one used above.
With our Condition action, I will firstly cover the Yes branch. Create within it an “Apply to each” called “Apply To each Attachment”, as below.
The first action we will use is “Get file meta data using path” and under the image will be all of the expressions and format for the dynamic data within.
This next step is one of the key aspects to the workings of this Flow. Before I cover the “Create sharing link for a file or folder” I will skip on one step and show you a single field from the “Update task” action. The field in question is “Reference Resource link – 1”. Here is a tiny screen grab of that.
The above is looking for “A valid URL based on the HTTP/HTTPS protocols”, an online image basically. One that we have permissions to view. Testing with this showed me that I could add a file from SharePoint, OneDrive and the web so I got to creating a “Sharing Link”. The same Idea as what you would generate if you were to share a file with a colleague from the GUI.
Let’s update the task ….
For the No branch, we still have the task description to update regardless if there were no attachments in the email. Another aspect of “Create task” that is not available natively. I like it that way, it encourages getting back the data from which the trigger created. I favour this method with all connectors as it just sits well with me and it’s a technique that I see regularly mentioned in the forum. For example, “I have started with a trigger item in a list but how do I get to the stuff”, kind of thing.
We have now reached the end of the Flow creation and it can now be tested. Let me refer you back to the start of my post were I displayed the sent email and the “sneak peek” of the Planner task. Here is the task.
I have highlighted in red all of the parts that were generated by the Flow with some data captured from the email and some from expressions relating to time and date. But there’s one missing part that has featured above but has not yet had any limelight, the all important SharePoint Library.
Not only can files be created in SharePoint, but folders too. This is what we were gearing up for when we created the TimeStamp variable and returned Current time at the start of the Flow. It is entirely possible that duplicate tasks of the same name could be generated in error, or multiple tasks could be created on the same day, so the hyphenated time stamp that we see makes sure that each folder created within PlannerDocs is unique and builds a repository of all attachments linked to the Planner tasks.
So I hope you have found this post useful and helpful and can maybe see yourself implementing it one day too.
Please leave any comments below and if you come across an issue or need some assistance, please post in Get Help with Microsoft Flow and reference this post and either I or another in the community will be happy to assist.