cancel
Showing results for 
Search instead for 
Did you mean: 

Create Planner Task and Include Attachments From Outlook Email

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 connections.

 

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

triggerBody()?[‘Subject’]
utcNow()
addDays(utcNow(),7)
triggerBody()?[‘To’]

 

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.

 

equals(body(‘Get_email’)?[‘HasAttachment’], true)

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”.

outputs(‘Compose_Sub_Folder’)
items(‘Apply_to_each’)?[‘Name’]
items(‘Apply_to_each’)?[‘ContentBytes’]

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.

equals(body(‘Get_email’)?[‘HasAttachment’], true)

 

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.

variables(‘TimeStamp’)
body(‘Get_email’)?[‘Subject’]
items(‘Apply_To_Each_Attachment’)?[‘Name’]

 

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 ….

body(‘Create_a_task’)?[‘id’]
body(‘Html_to_text’)
body(‘Get_file_metadata_using_path’)?[‘Name’]
body(‘Create_sharing_link_for_a_file_or_folder’)?[‘link’]?[‘webUrl’]

 

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.

 

Thanks, Alan

AlanPs1.io

Comments

Fantastic bit of work - Solutions for everyday problems 

Any ideas on how to modify this workflow to include attachments that are already in Sharepoint?

I have a Powerapp form where users can submit text requests along with attachments, and I am able to create and update a task in Planner with the information, except for the attachment. I figured out how to link to the List item, but not any attachments.

Hi @rharris , thank you for your post.

It would be best to post your request in Get Help with Microsoft Flow and reference this post and either I or another will assit with your customisation. Post some pictures of your attempt at customising and we can go from there.

 

You probably need the "Get attachments" SharePoint action with maybe some condition to target the one you want but hard to say without the full conext so a post in the forum will get your request more exposure and I'm sure the community will be there to help.

 

Thanks, Alan

Hi @AlanPs1,

 

I was wondering if there is anything I can add to the flow, that strips the subject line from invalid characters before creating the path on sharepoint. 

 

The flow failed a couple of times because on the subject line there was a colon (Smiley Happy

 

Thanks

Hi @CharlieC ,

Thank you for reading, implementing and I am very glad you have this working ... well aprt from the colons in your titles.

 

Here is a method I use - https://www.alanps1.io/power-platform/flow/flow-stripping-unwanted-characters-or-special-characters-...

 

You will need to implement it to suit your process but it should help you remove the unwanted colon and more.

 

Thanks, Alan

This flow works great.  My only concern is when the original email is replied to it also cretes a new task.  Is there a way to:

  1. Only create a new task for the 1st email of that subject line that is sent
  2. Add additional emails replied to in the comments section of the new task that was created

 

@k_gabriele I think this is due to a recent update on the planner notifications, as it used to work fine for us but recently it started to create a new task for every comment made. 

 

I had to pause the flow till I find a solution.

Thanks for this great post! I'm trying to set up a similar flow and am getting a "BadGateWay" error when attempting to creat the file in SharePoint in my PlannerDocs Folder. The error Status code is a 502. I'm trying to find documentation about it, but am coming up short. Any ideas? Is there perhaps something wrong with my set up on SharePoint?

Almost got it to work but the final scope is throwing an error in the "Update Task Details When Email Item Has An Attachment" section. Here's the error message, 

"Schema validation has failed. Validation for field 'References.Reference.Alias', on entity 'TaskDetails' has failed: The field cannot be longer than 100 characters." Know any way around this @CharlieC ?

 

Meet Our Blog Authors
  • Working daily with Microsoft Cloud to deliver the needs of my company, my customers and various Microsoft communities and forums. | Office 365 | Flow | PowerShell | PowerApps | SharePoint |
  • Co-founder of https://plumsail.com, Office 365 and SharePoint expert. Passionate about design and development of easy to use, convenient and flexible products.
  • Microsoft Business Apps MVP. Owner of ThriveFast, an Office 365 consulting company.
  • 7x Microsoft Business Solutions MVP (CRM)
  • Solution Architect with Slalom, and organizer of the Boston Office 365 User Group, and long term SharePoint/Office 365 veteren. Find more at http://www.davidlozzi.com. Follow @DavidLozzi
  • I'm keen in MS technologies, SharePoint, Office 365 and development for them
  • Daniel is a Business Productivity Consultant & Microsoft Business Solutions MVP who is very enthusiastic about all things Office 365, Microsoft Flow, PowerApps, Azure & SharePoint (Online). Since the preview, Daniel has been working with Microsoft Flow and later on with Microsoft PowerApps. That led to him being awarded an MVP Award for Business Solutions. He loves to blog, present and evangelize about improving productivity in the modern workspace with these amazing tools!
  • Michelle is an Office 365 solution architect in Twin Cities, MN. She has been delivering business collaboration solutions for years with her focus on SharePoint and Office 365. Michelle is a recent board member of the Minnesota Office 365 User Group and has been a member of the SharePoint community since 2009. She is a frequent speaker at MNSPUG and SharePoint Saturday and co-chaired the Legal SharePoint User Group for 4 years. Her most frequent projects have involved rolling out a large deployment of Office 365, SharePoint Online intranet, build of a "CHAMPS" Office 365 user adoption program and most recently, SharePoint On-Premise to Online Migration. Michelle is very excited about cloud technology as it is shifting her IT Pro focus to collaboration strategy and technical adoption.
  • I'm a Microsoft Office Servers and Services MVP with a special interest in SharePoint, Office 365, Microsoft Flow, Microsoft Teams and PowerApps. I work at Triad Group Plc ( https://triad.co.uk)
>