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

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 (:)

 

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

Anonymous

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

 

@Anonymous 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 ?

 

@L1saD Haven't seen that error before but might worth checking your character length of the attachment or the email subject line? It says that it's over 100 chars

Anonymous

Hello this is very cool and i tried it a couple of months ago and works really well. But now i tried to do this again for another flow and i get error 

502  
"message": "BadGateway",
"message": "Cannot create folder etc etc".
When i remove the "output" from the Create file section it works saves the file but dosent create folder or anything. Any help is appreciated.
@jco10  Having the same issue did you manage to solve it?error flow.png

Hi @AlanPs1 ,  We got ours to work but it does not like spaces in the subject line (if it does have spaces in the words, it sends the attachments to a New Task (Title of the task is always named New Task) )  Have you seen this before?

Your solution really helped me a lot in my work ptoject, thank you so much. @AlanPs1  Is there a way to use your solution with attachments from Teams instaed of email, the trigger will be "When a new channel message is added"? This will happen if a user sent an email to a channel in teams, if it contains a an attachment it should attach it.

I can't seem to find anything regarding editing the checklist anywhere online. Any clue as to how to add items to that?

The below expression is apparently invalid when trying to add into the inputs field on the compose sub folder. 

 

Guessing im doing or have done something wrong?

 

concat(variables(‘TimeStamp’), ‘-‘ , body(‘Get_Email’)?[‘Subject’])

 

This solution doesnt seem to work for me? any assistance ? 

Hi all, firstly thank you to the author for sharing this explanation. I have tried to recreate this flow but am receiving an error as shown below. Can anybody advise what I might be doing wrong?

 

Thank you

Tom

Screenshot 2019-12-19 at 09.16.02.png

Anonymous

@AlanPs1 Thank you for your tutorial. I tried your method and successfully created a task from email with subject and body content. However, I cannot create the folder to store the attachments. It seems like the automation cannot recognize if the email has attachment or not. Could you help me to fix it? Thanks.Capture.PNGCapture2.PNG

Hi @Anonymous . Best thing to do is post in the get help threads referencing this post and someone will assist. Thanks, Alan

@Anonymous  Post your top part of the solution let me try to help. The issue might be with your email steps.

@tomsutherlanduk   upload the solution, not ran results, let's see. Your issue is parameters. Let's help. 

Anonymous

@AlanPs1 @Sam_Madisha Thanks for reply. I just posted my issue on 'Building flow' forum.

https://powerusers.microsoft.com/t5/Building-Flows/The-flow-cannot-recognize-if-the-email-has-attach...
Please help. Thank you.

Is there a process to apply this flow to emails sent to a channel email address that appear as a post? I currently have a flow that creates a task in planner but I cannot get the attachments to move to the task.

 

Thanks

Jason

Anonymous

Hello

 

I also had the problem that the equals(...) condition and the compose sub folder branch did not work.
I guess it had something to do with the fact, that there is a new Version of Get Email (V2) and the Name of the function is not "Get_email" anymore.

 

Capture.PNG

 

I tried to have a look at the code of the V2 and then tried to use the equal-function with "Get email (V2)" and "GetEmailV2" as seen in the code, neither of it worked out.

Do you have a solution for this?

Use “Get_email_(V2)” instead of “Get_email”. I’m sure that’s it but don’t have it in front of my but to test use compose and peek code and you’ll see it’s name to be sure whenever MS have brought out a new version of any connector.
 
Thanks, Alan

I tried to copy all the steps, but I kept receiving failed message. And the flow created 2 same tasks on my planner, both without any attachment. Not sure where I did wrong.

 

註解 2020-03-06 185928.png

Hello, @AlanPs1 

 

Thank you for this great guide!

Hello, @AlanPs1 and thank you for the tutorial.

 

I'm having problems with the upload of the attachments. It's seems i'm creating new files with the name of the attachment but the file content is not uploaded. Any suggestions?

2020-04-23_16h13_55.png

Hi, 

 

I got the flow working a couple of times. But now it get´s stuck at the first scope ("Scope If Email Has Attachments Save to SharePoint"). 

 

When the condition ['HasAttachment'] is true it times out after ~15 min. No files are saved.

If the condition is fales it works. 

 

What to do?

Hi, Thanks for this walkthrough, it has been very helpful!

 

I have replicated this flow (using "Get email (V2)") with "Include attachments" set to "Yes" and it technically runs successfully other than that the conditions always evaluate to "False" even if the email has attachments. (It successfully creates the task and copies the message body to the task description, it just won't seem to pick up any attachments.)

 

I tried switching the condition so it results in "yes" on "false" rather than "true" but this has an error in that an object of type "NULL" is passed down rather than the expected string, which implies to me that "Get email" is not successfully including the attachments (both "Get email" and the trigger have "include attachments" set to "Yes". 

 

Any idea why it would be doing this?

Hi Alan,

 

I have tried to replicate the above flow but the condition always evaluates to "false" even when the email has attachments. The "include attachments" option is set to "Yes" for both "Get Email (V2)" and the trigger action. The task is created and the description populated it just doesn't transfer the attachments.

 

Any idea why it is doing this?

Hi @AlanPs1 ,I've done the whole process but I am getting an Error on Compose that says: Correct to include a valid reference to 'Get_Email' for the input parameter(s) of action 'Compose'.

 

Could you please help me?

 

Thanks in advance

Thank you @AlanPs1 this worked for me! 

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.

@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?

@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

 

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!

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

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.

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  

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? 

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

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/