Skip to main content

Notifications

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

*This post is locked for comments

  • muzietto Profile Picture muzietto 19
    Posted at
    Create Planner Task and Include Attachments From Outlook Email

    This is all quite interesting !!

     

    I have a slightly different case: when I receive the file with the attachment, I need to read the attachment file content (it is a plain ASCII text) and compose an HTTP POST request where the attachment text becomes the body. In other words, I'd like to manipulate the attachment content as soon as it arrives.

     

    My post is at https://powerusers.microsoft.com/t5/Building-Flows/How-to-make-a-POST-HTTP-call-using-the-text-content-of-an-email/m-p/2742846#M308547 

     

    I already received a comment saying that I should go through Sharepoint.

     

    What would you do? 

    Cheers.

  • The-Dark-Jedi Profile Picture The-Dark-Jedi
    Posted at
    Create Planner Task and Include Attachments From Outlook Email

    This is fantastic.  Do you know how to tweak this so that the trigger is an email sent to a M365 group mailbox?

  • KWalker Profile Picture KWalker
    Posted at
    Create Planner Task and Include Attachments From Outlook Email

    Hi,

    Thanks to @AlanPs1 for the step by step.

     

    Is there any way to update the Planner task details to uncheck the "show on card" for attachments? 

  • Jajina Profile Picture Jajina
    Posted at
    Create Planner Task and Include Attachments From Outlook Email

    Hello,
    @AlanPs1 I did this flow, everything work great but I have no preview of the file on the task. I only have to click on attachment and open in another window to see it. 

    When I create a task manualy and attach the file and choose preview I see the miniature on the task board. Is this normal when I create a task from e-mail or is there any possibility to solve this?

     

    Thank you.

     

    Jadwiga  

  • WP-18091706-0 Profile Picture WP-18091706-0
    Posted at
    Create Planner Task and Include Attachments From Outlook Email

    As with everything Flow related, any content has diamonds that can be harvested even if the topic isn't spot on.  I'm ultimately trying to figure out if I can create a quick action from outlook to act as a trigger for copying an email into a MS Plan.

  • bg69671 Profile Picture bg69671
    Posted at
    Create Planner Task and Include Attachments From Outlook Email

    Hello,

     

    I am having issues with the formulas at the 'Condition if Attachment Exisits" and "Compose Subfolder steps:

    bg69671_0-1649249785646.png

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

     

     are showing as invalid.

     

    bg69671_1-1649249910526.png

    Does anyone have any advice?  Thank you very much in advance!

     

    Thank you,

    Brett

  • JaySchlegel Profile Picture JaySchlegel
    Posted at
    Create Planner Task and Include Attachments From Outlook Email

    Hey All,

     

    @AlanPs1 everytime in the Create File section when i add file name (Sharepoint file name dynamic content) and File Content it automatically creates a new Apply to Each 2 step above the create file.  

     

    Basically everything works great to create the card in planner, with subject title, body but the Attachments are NOT showing in sharepoint or the planner card created? 

     

    ----

    UPDATE - I figured it out - however @AlanPs1 Attachements are not pushing to sharepoint, thus in turn not pushing to the task that is created.  everything else works great with title, due dates, body text etc. PLEASE HELP!

  • ARC_afabozzi Profile Picture ARC_afabozzi 26
    Posted at
    Create Planner Task and Include Attachments From Outlook Email

    @Akjohnson625here is what I did although I am not sure it is the best solution.

     

    My upload file question is called Optional: Screenshot of Issue

     

    I created a condition and stated if Optional: Screenshot of Issues contains name then do the code I want.

     

    screenshot_question.png

     

    I tried using null, Null, or NULL but it would not work for some reason. I chose name because it gets returned in the JSON when a file is attached:

    Compose.png

     

  • Akjohnson625 Profile Picture Akjohnson625
    Posted at
    Create Planner Task and Include Attachments From Outlook Email

    @AlanPs1 i am trying to get this flow to work with get emails V3 and when I try to html to text it creates an apply to each.

     

    This throws the whole flow off. Any fix with newer versions?

  • DanThomas9 Profile Picture DanThomas9
    Posted at
    Create Planner Task and Include Attachments From Outlook Email

    Hi @AlanPs1 great flow!  I would like to see this exact same flow with the flagging of an email which is what kicks off the process.   On top of that the option to determine your task buckets they fall into by using outlook categories.  That would add another amazing possibility to organize tasks within outlook.