Sending email with attachments from SharePoint list - Power Automate recipe

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone in this video i'm going to teach you how to use power automate or microsoft flow flow is the old name how to use power automate or flow to send email attachments from sharepoint list so scenario that you will see here is imagine that you're building an app like issue tracking app using powerapp platform a power platform and you want to these these issues also have some kind of attachments so these items have some these kind of attachments as you can see in the screenshot here and every time that item or that issue is modified or new item is created you want to send an email to someone to notify and also send these attachments in the email it's a very common scenario you'll learn a lot by doing this i will also show you first how will that flow will look like but before that let's see what topics you will learn by building this flow so topics you'll learn is you'll learn about concepts of variable array variable if you're not familiar you have to do some initialization and appending we'll go through all those concepts a very important concept that you will learn here is how to get the attachment content from sharepoint list and it's a two-step process and you'll see that in the first step you only get the list of attachments and then you'll have to get the actual content of it very very important third very very important point is json format and you have to use the right json format for putting the content of these attachments in an array variable so that you can use it in the next step which is attaching multiple attachments in the email it becomes very simple if you have just one attachment but for multiple attachments it gets a little bit complicated and of course you will see how to do a quick testing so let's get started uh let me first show you how will the built app look like so this is the flow but before i show you the flow is the sharepoint list this sharepoint list as you can see it's a test list test list that i created which is issue tracker right now it has only one issue very simple test issue the important part here are these two attachments that i mentioned once the flow works successfully you'll get this kind of email which says that your issue was a new issue was created or modified you can put the name of the issue but most important are the attachments that i have there let's also walk through this is the last flow that i ran while testing it exam examining this will help you a lot to understand what happens here and when i implement some steps you'll better understand why i'm doing some of those things so of course the trigger as you know each power automate or each flow has something called trigger what actually kicks off this flow so trigger is when a new item is created or modified nothing fancy here by the way you can always use output click to download to examine more i am not going to do it here now here comes the important part getting the attachments so for this item which was created you first get the list of the attachments so as i mentioned earlier you you're first getting the list and list is as you get when you examine the outputs you will see it's an array with multiple json objects and this is like one json as you can see within curly bracket this json has things like id of the attachment uri display name and blah since we have two attachments here's another object in this array this is another json same format and it has different display name so understanding this is very important because we'll use these concepts when we actually create this flow then you have to initialize a variable which i named it attachments it's an array type it's an empty empty variable at this time but you have to initialize before you can use it now in this step you're getting list of attachment for just the list not the actual content so in a loop now for each of those attachments in the list you will get the content and for that you'll this use this action called get attachment content where you'll take the input of this file id that you had in this one by one get their content this is the value you will get in the content and then this value you will append in this array variable so that one by one in this variable that you created you are getting these attachments the name of that attachments and content byte now this structure is very very important i'll emphasize this again and again in this video there's no like real computer science concepts it's like that's how the flow has been implemented that you have to use this specific name and content bytes here these are the actual field names that you have to use when you append these json object in this array so that it works well in this next step where you have to send email and you also have to put something for the attachments so you put some array with these objects and i'll emphasize this again and again this is this is very very specific to this requirement in a future video when i'll show you how to create these attachments sorry how to attach these multiple attachments in approval workflow you have to use slightly different json format now you might wonder why i don't have a good answer for that it's just the way flow is implemented so hope this gave you a good idea of what we will build let's start building i'll put this in edit mode now so that i can keep copying few concepts and i will create a new flow now so let's go to create the different kinds of flow you can create here i'll not cover all these in detail for our purposes we have to use automated cloud flow what that means is we are not manually triggering out anything since this will be triggered when uh when something is modified or created in sharepoint list we're just using this that's what it means here okay so automated i can use some of these things but i'm choosing to skip it so that i can show you exactly how to do it from scratch so i'll skip this part and go to creating this flow from scratch okay so first step as you know for any flow it's uh it's what triggers this flow uh so before i speak further one thing i must apologize i keep interchangeably you keep using the terms flow and power automate because flow is the older name of power automate they essentially mean the same thing uh you'll see many videos and many articles also on the web talking about flow sometimes they talk about power automate just because microsoft changed the name flow somehow feels more natural to me that's why i'll use that term but they all mean the same thing just in case you're wondering what are these two different things all right so for this trigger our trigger is sharepoint so i'll choose sharepoint and for sharepoint when do we when do we trigger this when an item is created or modified so i chose that all right i will not use any of the advanced options for this okay new step what's the next thing we should do here let's look at this flow and what did i do earlier get the list of attachments yeah obvious so i'll get the list of attachments what that means is anytime a new item is created or modified that means for this purpose if i modify this item i should first get the list and like i mentioned earlier getting the list doesn't mean that you're getting the content as you will see when i say get attachments you see two options here get attachments get attachment content we'll use this content also later but for now just get attachments okay so i got the list of this will help me get the list of attachments i have to provide some inputs so name of list sorry name of site name of the list and id okay so which what id i should give here this id is the id of the item for which we are getting the list of attachments so what that means output of this so when i select this dynamic content i wonder why i am not getting this content that's weird uh usually we should oh because i did not okay so here's the mistake i made i did not select the site and the list name here that's why it was saying no dynamic content and i was wondering what's going on okay so now it should get it okay yeah so when a new item is created or modified id of that so at the end of this step i am getting this is a trigger and getting list of all the attachments and the next step for me will be to just looking at this initialize the variable the array variable that i mentioned let's do the same i'll look for variable and variable has different kind of actions for using any of the variable first thing you always have to do is initialize so i will initialize this i can put any name but just to keep it logical i'll say attachments but i don't have to call it attachments now there are different types of variables these are types that microsoft power automate supports we'll use array i'm not giving any value i could have but since in this case we'll start with empty array i can just leave it as it is so you're done with this action next step so now you have your list of attachments you have an empty array to fill the value in i will now need to get the content of this so i'll go back to again attachment content and i get this get attachment content i'll select this so this is this is asking me again uh what is the sharepoint site what is the list name it feels very repetitive now there are two uh i got confused initially when i was trying to figure out what those ideas are so it's important to pay attention here this id says id of the list item from the file list item the file is attached to this means this is the id of the item by item it means this sharepoint item overall so that means this is output of this first step this is file identifier for the attachment so that means the file for which you want the attachment that means this is the id of the file that we will have here so these two are dynamic content that we will take as the output of previous step so id of the item so when an item is created or modified and file identifier is from the get attachment step what is the id of the file so now you got the attachment content you you will notice that as soon as you do this power automatic automatically puts this applied to each it's like a loop which is which is a delightful intelligence that i liked uh power power automate automatically recognize that you forgetting the content since the this is a list of attachments you need to do it in a loop so it automatically inserted this loop all right so we are done so at the end of this now if you notice here we are done with getting the attachment content now we have to put those attachment content one by one in this variable that we initialized this attachments variable so add one more action within the same loop pay attention to this you have to do it in the same loop because if you do it outside you will lose the opportunity to keep adding those attachments one by one to this variable all right so this one let's look for variable and we want to append something now append you will see has two things array or string for our case we are appending it to array variables so we'll choose append name of the variable is same as what we chose earlier and value this is very important because it's very important to get the format right you'll create a json object here so json as you know is enclosed within curly brackets so i first created empty curly bracket the first field name that you have to use is name as you will see here and i'll just repeat it again and again very very important to get this right because if you don't get this right even if you make some spelling mistake miss some quotes power automate will not give you very good error message so it will very confuse you but your this step will fail because this email step expects attachments in a very specific format and just to jump the gun in this step email apart from two and subject which are simple you have to use attachments here and that will be variable and it expects variable with json in a very certain format and as you will see when i will in future video when i'll do attachment for workflow that json format will change you have to use a different format it's a very weird implementation from flow side i guess but this is how it is for you to make it work you have to follow what they expect all right so name what should be name of the file this is the name of the attachment so when you get the email these attachments are attached with some display name i use the same name that the sharepoint list attachment has but i don't have to i could have chosen any other name it's simpler and makes more sense to use whatever was the display name of this file how do i get that display name dynamically very simple it should be output of one of the previous step and output of that is when we got the attachments apart from id absolute uri we also got the display name so i'll say display name next next is again at the risk of repeating and i'll keep doing that again and again i have to use this exact term here so i'll say content bytes colon and what will be the byte so this byte is the actual attachment content so when i showed you earlier at the end of this step let me show you the previous run just in case you forgot i don't need to save this so in the previous run just to show you what we are expecting for this attachment content for each of these attachments attachment content the output of has two fields in the json one is the type so what is the type of the attachment this helps computer know what to do with this attachment type but the second very very important you will see this content having some very gibberish kind of gibberish kind of text here it's it's a binary text of the attachment so the attachments that we have here like csv file or png file behind the scene computer machine translated that into a binary code it's like a machine code that is there to encode this special attachment and machine knows with the content type and content what to do with that how to read that and this is the content that you have to put as the content bites here so that machine knows when the email step has to use it they know how to read it so okay so with that introduction content bytes will be this attachment content so attachment content and that's all so what this will do is for each and every attachment it will create this json object and put that and append that in this array variable so that's all about this step so at the end of this step now what you have done you have you have got a trigger you got the list of attachments you created an empty variable array type to hold all the attachments and in the loop you're getting the content of the attachment one by one and you're appending that content to this variable that you initialized so at the end of this step this variable attachments now has list of all the attachments with the name the last step that you have to do what i normally recommend when you are implementing is don't wait for all the steps to be over what i personally like to do like save it and i do some testing to see how far i have gone are things working properly up to this step before i do further it's always to do things incrementally that's a good development practice but in the interest of time for this video i'll do the next step as well but i strongly recommend that you don't wait for everything to be done before you test anything all right so last step that i have to do is send email i already got the thing okay send email office 365 there's some problem with my account here so i'll use a different account don't worry it's nothing to do with power apps it's just because my office 365 account has some misconfigured setup this is a test account you will probably not face this issue it's nothing to do with flow all right so two and i will send this email to in this case my own account which is a test account three dot okay i'm typing this right okay so subject of the email you can put any subject but here i will say issue created or modified if i want to make it specific i can also put this the actual title of this issue so i'll say title and here i can say title and put the actual title of the issue again i can also show the description totally up to you what you want to send in the email these are very simple things i can also get a little bit fancy to put title and description in bold these are the things that low code solution like power automate makes very simple and i really love i could just make things bold now i can draft the email so these steps were very simple for sending email so far you said who do you want to send this email to what should be title what should be subject of the email what should be body and you're good but here comes the tricky part is how to attach those multiple files that you have when you expand it expand the advanced options so i'll show it again show advanced option when i expand that you'll see attachment one content one can keep keep on adding new items so but now i'm confused what do i do here uh how i have to have multiple attachments how do i keep manually doing it because i have to dynamically get the list of attachments and that's where this this button on the right will come to your rescue it's very very important to pay attention you cannot do it manually one by one for this use case you have to use some kind of automation here so click on this and you will see that now you can put everything in so i'll show it again here you have to do it one by one you see this hint of the button which says switch to input entire array that means you can do it using array when i clicked on that i got this view attachments attachments click on this you'll get the variable attachments this is the same variable that we were populating earlier great attachments and that's it so now you have an email with subject body 2 and the attachments that we had earlier and this was the last step if we did everything well if i save it you should be good so let's let's test it so click on test since this is the first time we'll be running it we cannot use data from previous runs so i'll perform the trigger action and i'll say test what is the trigger action here i'll do very silly thing here is triggers somehow modify this list item somehow so here i had tried this earlier so i just put this fake one here i'll just modify it here tab out and it's saving so that means this flow should have been triggered and it's taking some time but you will see probably that yeah it says flow trigger flow ran successfully will see the result and i can see an email notification where i get this email which says issue created or modified the display name of the first issue and you can examine more details of what you got here so that's all about implementing this hopefully this gave you a good idea of how to use these different concepts i'll also talk about few important things because many people make mistake one is getting attachments is a two-step process one is getting the list of attachments with information like id display name blah blah blah but the second part is very very important where you get the actual content of those attachments in a loop and then you put that in array array okay so for it applies to any variable but for array also you first need to initialize before you can append if you directly go to appending you'll wonder why i can't put any variable name you have to initialize with empty value and last probably the most important part and this will become any important even in the next video when we do similar implementation for approval workflow is you have to use specific name in the json specific field names in the json object so that your email sending steps work or step works that is make sure you have name within quotes make sure you have content bytes name is a display name content bytes is the actual binary that you get through the actual content of those attachments so hopefully you found this video useful in the next video i said we'll talk about how to do the same thing but triggering the approval workflow it's very common scenario for issue tracking or any kind of ticketing system where you may want to create an item in sharepoint you may want to attach multiple files and then trigger a workflow where some approver has to approve it before you can take further action so we'll see that in the next video hope this was a good use of your time stay in touch by subscribing to our youtube channel so that you don't miss any videos like this we also write regularly on medium cloudatica.medium.com feel free to email us at hello claudettica.com for any questions any help or visit our website cloudedica.com thank you have a great day
Info
Channel: Cloudatica
Views: 13,018
Rating: 4.941606 out of 5
Keywords: Power Automate, Microsoft Power Automate, Microsoft Flow, Attachments in Flow, SharePoint Attachments and Flow
Id: yy1z7cZ5Dac
Channel Id: undefined
Length: 25min 18sec (1518 seconds)
Published: Sun Dec 20 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.