 Hello, everyone, and welcome back to another video. So today's video, we're going to be continuing our look at Power Automate. So the solution today is, we want to run this automation every time a new email is received into our mailbox. So if you haven't seen our previous video, you might want to watch that to see the early steps of how we got to this page. But if you haven't, and you're slightly familiar with Power Automate, all you need to do is make sure you've got the application open, go into My Flows, and then you'll have an option up here to start a new flow. But for us to save time, because I believe this video may go on longer than normal, we're going to just jump straight into it. So the first thing we want to do is look for our particular trigger. So for us, we want to run this when an email arrives. So we'll go new email arrives, and hopefully that should give me the options I'm looking for yet. So the first one here for Office 365 Outlook, I'm using this scenario, going to be when a new email arrives. So we should select that. And you can see that it's obviously got the inbox selected as our default. So if you had any logic set up in your mail account already where these particular emails are getting stored in a particular folder, you would need to select that folder from here. But for us, we'll keep it nice and simple and we'll go straight to that inbox folder. So if you look in Advanced Options, this is allowing us to now apply some criteria. So rather than just run this automation against every single email that comes in, we want to be a bit more organized than that. So the first thing we're going to do is apply a subject filter. So of course, you need to make sure that this process is in place already for the email receiving. But for us, we know that our email of interest is always going to have the subject of daily attachment. So as long as that's contained in the subject, this will trigger. What we need to also make sure we do is include attachments. So we want that attachment information to be retained when this is picked up. And also only with attachments, we want to make sure this is selected as yes. So in the scenario that we receive an email with the subject daily attachment, but it does not contain any attachments, this will not trigger. In order for this to trigger, the subject has to be daily attachment and that has to be something attached to that email. So once we're happy with this criteria, we can now move on and do our next step. So the next thing we want to do once we've got the email and we can see it as attachments is we want to apply some logic to each one of those attachments. So simply we wouldn't do it as a type apply to, and it should give me apply to each for do that. Yep, there we go. We can see we now got the option I'm looking for. So this one here, apply to each. So what do we want to apply to each? We want to apply something to each attachment. So all I'm gonna do is from this list that's now popped up for us, which gives us all the elements of the email. We go right to the bottom and select this here attachment. So the file attachments for the message. So we'll select that like so. And what do we now want to do with each attachment? Well, we want to create a file. So we'll go add an action. And simply all we'll do here is type in create file. And one of the options or the one option we're looking for here is SharePoint. You could of course do this on OneDrive, but I'm gonna stick with SharePoint for the time being. So all I need to do here is create file. And now it's gonna ask us for that SharePoint criteria in which where to create this file. So simply all you need to do is select our SharePoint address. For me, nice and simple, I've only got one SharePoint location. And then I'm gonna need to provide the folder path. So for me, let's go into the folder icon here. And I know I've got a folder set up called test archive. Well, a document library in fact. If I go into the arrow, it will show me all the folders in there. So I'm gonna select daily email. And this is the location we need. So the next thing when I go into file name, I don't want to type this. I want dynamic. So I want to just pick up the information we already know for that attachment. So if I go into my list here again for all the elements of the email, if I scroll towards the bottom, actually towards the middle somewhere, you can see we've got this option here, attachments name. So if you select that, what it's gonna do is just name this new file on SharePoint exactly the same as it's named as the attachment onto our email. And lastly, file content. So if we now select that, you can see it's great, it's populated already for us. It's identified that this being content. We're just gonna select attachment content and as the content for the file. So quite simple, we can step through this. We know our criteria here for the email. The next thing, obviously, we want to loop through each one of the attachments on this email so they're applied to each. And for each of those attachments, we're gonna create a copy of that on our SharePoint library supplied here. Once we provide that, we can do hit save. And we'll get a nice green bar once we're happy it's saved, perfect. And of course, we just now need to test it. So let's go into test. We're gonna do this manually, select test. And you can see it's instructing us now to see this to work. We need to send a new email to our inbox. So we'll just send an email to ourselves. And as I've got my email inbox here, so let's just do a new email. So new message, let's go type it to myself. So my subject is daily attachment. Cool, what we've got there. And then all I'm gonna do is just drag a attachment I've got to hand. So let's add that to the email. Once it's uploaded, if we hit send, and we'll see it's come through hopefully yet, we can see our email has now been received. So subject daily attachment with a file called staff upload. If we go back into our flow and maybe give us a couple of seconds just for it to reflect that an email has come in and also just to work its magic. And then hopefully we will see a green bar at the top there to say it's run successfully. Yep, that's just now come through. And we can also see a tick against each of the actions so we know that each of those has run. And usefully, we can see that it took two seconds in total. Well, for this particular thing, but obviously in total here for it to have run. So lastly, let's go to our SharePoint directory as we've got here. So our daily email folder, nothing's come through, but maybe just a quick refresh. And there we go. We can see that our file has now been created and stored for us in the SharePoint document library. So everything has worked as intended. So the next thing to bear in mind is this has worked great, but what if, well, what will happen when the same email is received tomorrow? Well, obviously at the moment, it's gonna either override this file or call it some name convention that's not gonna be overly useful, like staff upload one, two, so on and so forth. So let's just make quick change in how our file is saved. So let's go back into edit. Now we're back in Power Automate. And you can see we've got file name here. So what I'm going to do is just add a bit of logic to this. So if I click in front of this file, we'll actually just remove for time being, if I click into here, having removed the name, what I can do is go in and do a quick expression. So if go expression, and I'm gonna type into here format fade time. The reason for doing that is I want to format the current time at which this pipeline or this flow is going to run. So what do I want to format? Well, I want to use UTC now, which is going to return our date time. But the reason for using format is if I was just to use UTC now, what it would do is it would give us a date timestamp, which isn't all the most clear. But for this example, and to keep it short, I'm just gonna format this into a recognizable date format. So within single quotations, I'm gonna type the year and four characters, the month and the day, like so. And then what I will also do in here is I'm gonna just put this in a concatenated function. So let's just do concat at the front, because I want to take this content and combine it with an underscore. I need to do in single quotes and then close brackets. And then when I hit enter, this should work for us. Yeah, we can see it's worked happily. And then the next thing I want to merge in with this is I want to take the file name and sticker at the end. So all I'm gonna do here is go into the attachments, where is it attachment name? So we've got attachment name there. So we've got this concatenated element here, which is our date with the underscore, followed by our attachments name. And this should help give us a unique identifier that's gonna update with each day this is run. Let's now just click save and make sure that's worked and happy okay. Cool, so the next thing to do once again is to test. So manual test, cool. So we just need to do another email. So go new email and send it to myself. Daily attachment, let's drag our attachment in. Great, and then let's send that. Wait for that come through. Great, so we can see the emails come through. We can go back into Power Automate to wait for that to acknowledge that the new email has been received and obviously for it to perform its actions of getting that attachment and saving it in our SharePoint document library, which should probably only take two or three seconds. Perfect, we can see our flow was run successfully and we can see both elements have got the green tick beside them. So let's go back to our SharePoint document library and now let's do a refresh. And now we can see that that file has been stored there once again, but this time we've got a nice little unique identifier of date at the beginning of the file name. So as this email is now received tomorrow, which will be the 23rd of August, it won't override the file, but we'll see a clear indication for it being the 23rd of August when that is received. So I hope you enjoyed that video. If you did and it maybe gave you an answer to a question you're searching for, please don't forget to give the video a like. Not only does that help that all-important YouTube algorithm, but it's greatly appreciated by me as well. If this is the first time you've found our channel, one of our videos, or you've seen them in the past, please don't forget to hit the subscribe button, also that bell notification button, that way you'll be notified of all of our videos as they come out in the future. If you do have any questions about this video, please do drop me a comment below and I will get back to you as soon as possible. So once again, thank you very much for watching and we'll see you in the next video.