cancel
Showing results for 
Search instead for 
Did you mean: 
AlanPs1

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
About the Author
  • Experienced Consultant with a demonstrated history of working in the information technology and services industry. Skilled in Office 365, Azure, SharePoint Online, PowerShell, Nintex, K2, SharePoint Designer workflow automation, PowerApps, Microsoft Flow, PowerShell, Active Directory, Operating Systems, Networking, and JavaScript. Strong consulting professional with a Bachelor of Engineering (B.E.) focused in Information Technology from Mumbai University.
  • I am a Microsoft Business Applications MVP and a Senior Manager at EY. I am a technology enthusiast and problem solver. I work/speak/blog/Vlog on Microsoft technology, including Office 365, Power Apps, Power Automate, SharePoint, and Teams Etc. I am helping global clients on Power Platform adoption and empowering them with Power Platform possibilities, capabilities, and easiness. I am a leader of the Houston Power Platform User Group and Power Automate community superuser. I love traveling , exploring new places, and meeting people from different cultures.
  • Read more about me and my achievements at: https://ganeshsanapblogs.wordpress.com/about MCT | SharePoint, Microsoft 365 and Power Platform Consultant | Contributor on SharePoint StackExchange, MSFT Techcommunity
  • Encodian Owner / Founder - Ex Microsoft Consulting Services - Architect / Developer - 20 years in SharePoint - PowerPlatform Fan
  • Founder of SKILLFUL SARDINE, a company focused on productivity and the Power Platform. You can find me on LinkedIn: https://linkedin.com/in/manueltgomes and twitter http://twitter.com/manueltgomes. I also write at https://www.manueltgomes.com, so if you want some Power Automate, SharePoint or Power Apps content I'm your guy 🙂
  • I am the Owner/Principal Architect at Don't Pa..Panic Consulting. I've been working in the information technology industry for over 30 years, and have played key roles in several enterprise SharePoint architectural design review, Intranet deployment, application development, and migration projects. I've been a Microsoft Most Valuable Professional (MVP) 15 consecutive years and am also a Microsoft Certified SharePoint Masters (MCSM) since 2013.
  • Big fan of Power Platform technologies and implemented many solutions.
  • Passionate #Programmer #SharePoint #SPFx #M365 #Power Platform| Microsoft MVP | SharePoint StackOverflow, Github, PnP contributor
  • Web site – https://kamdaryash.wordpress.com Youtube channel - https://www.youtube.com/channel/UCM149rFkLNgerSvgDVeYTZQ/