Power Automate Tutorial - Expressions 401

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

This one is good.

👍︎︎ 2 👤︎︎ u/FakeGatsby 📅︎︎ Feb 17 2021 🗫︎ replies

"This is a premium feature."

--Every time I try to do something with power automate.

👍︎︎ 1 👤︎︎ u/podcastman 📅︎︎ Feb 17 2021 🗫︎ replies
Captions
[Music] what's up everybody welcome back john levesque here your host as always today i am joined by another awesome guest somebody who you have been demanding that i bring back so that we can have our fourth installment together bringing back reza durrani how you doing sir hello joanna i'm doing well how are you i'm doing good i'm doing good we're actually supposed to get some snow here in the pacific northwest which like a foot of snow which is crazy for us completely unheard of but me i'm excited about it i'm ready to take the jeep out and go and tear it up how about you how's things going over there things are going well i'm back in my hometown houston i believe the last time we uh did a video together i wasn't i was stuck in uh quarantine in california so i'm happy that i'm back to my own my own good finally back home glad to hear it man all right well we have had an overwhelming demand from people asking you to come back and do the fourth installment of our expression series the first three have had amazing results and success i hear that you're getting a ton of comments on your channel about it i get a ton of comments on my channel about it and so finally today i was able to get your back and i am very excited i think everybody's gonna be stoked to see the next installment of this so uh without further ado i'm gonna go ahead hand it off to you do me a favor just introduce yourself to everybody in case they haven't met you before and then go ahead and take it away my friend the floor is yours thank you john hello everyone uh if you haven't heard me or met me before my name is reza durrani i am a business applications mvp uh i work as a power platform practice lead at my organization catapult systems and i am very big in the community very big for the community let's put it this way and uh my goal is just to share as much as i can with the community that has given me so much over the course of the last three some reason well man great to have you super stoked to see expressions chapter four let's go let's do it and share my screen all right there it is all right so let's begin with expressions chapter four the first and i have three different scenarios that i have prepared for uh today's session and i hope that everyone enjoys all the three all three are important so let's begin with the first one the first scenario is around a flow run now when we build the flows in power automate we have a history of each run of our flow and this history is maintained for a 28-day period purely from a gdpr perspective and as part of this history many a times when our flows run if we would like to see a very specific case of a floor run so for example i have a flow running on a sharepoint list and i would like to see how did the flow run or what were the actions in that flow during the run for a very specific item now for that what me as the owner of the flow has to do is has to go to the flow go to the run history look at all the runs look at the date and time and literally have to guess when was the time and date at which that flow potentially ran and then go ahead and select that so i can look at my flow run and i can look at all the actions that were executed as part of that flow run a very common request is around error handling as well my flow has an error my flow failed now i have to go back to my flow and start clicking around and look at which ones failed and open that flow run now would it not be great if when the flow itself runs and depending upon your use case you can send a notification out or maybe store the information directly off the link to that flow run so if i select a flow run if you observe the url on the top that flow generates now because my tenant is built in the us region my url is us.floor.microsoft.com so you've got to be aware of your region so you can see your your url on top and in this case i have manage environments my environment name and id is right here flows i have the id of my flow runs i have the id of the run of the flow so these are goods the environment name is a good the flow id is a good that never changes these things never change what changes is this good that gets generated for each flow run now how do i go about grabbing all of this and storing this in my system of record or sending me a notification email whatever your use cases so let's look at how we can do that with the help of expressions so out here in my flow it's a very simple basic flow i'm just trying to explain the concept of the flow run link this flow triggers manually and all i do here is i just send a nice email to myself that expression 401 flow is running now and here is a link to this flow rug now how did i go about creating this link so right here if i go ahead and just add a very simple compose action or a variable right here just to print some information while the flow runs if i head over to the expression editor right here and bear in mind we've seen this in the previous chapters i have my experimental features turned on that's why i see this cool new expression editor experience and right here in this if i start plugging in a function called workflow right and as i was typing workflow if you notice it gives me this little information icon right here that says this function provides you details for the workflow runtime that means when this flow or this workflow is running i can grab a lot of a lot of details from this function and if you head over to the list of functions once again which takes us to the documentation and docs.microsoft.com and if i was to search for that same function right here called workflow you can see all the different properties that this workflow exposes for example the name of the workflow run which is nothing but the good that we are looking out for so what i will do right here is i will go ahead and plug in my expression now i already have this expression pre-built so i'll talk through this expression syntax the first one is concat and concat allows me to concatenate text the first text is hard coded and this is the url path right here in my browser url which is all the way up onto environments remember you might be in a different region so make sure you have the url correct next step i'm using that same workflow function and in that function there is an attribute called tags and in those i can grab some key data points one of them is the environment name and what this gives me is basically this name right here on the top which is my environment good next i append flows which is right here as per the url i get the id of the flow which is the name of the flow and then i append runs and give the name of the flow run which is nothing but the good that gets generated for each and every flow run and that is my expression and if i use this expression and that's exactly what i've used to send myself a notification email let's go ahead and run this flow so i'm going ahead and testing this flow manually right now so there should be i didn't even know about that workflow expression actually this is a little bit of a lesson for me it's pretty neat actually because it gives you a lot more information but right now the focus is purely just on that part but many times we need information about the flow run so it's gone ahead and sent me an email so let me go ahead and open my mailbox and here is the email that i just received and the email says that you know here's a link for you which takes me directly to the floor run now if i select this this will redirect me directly to that run not to the flow not to the edit experience of the flow but to that actual run that took place when i ran that flow and here is an example of that flow run and check the url that it generated let's open compose and see that same url and action right here right i got the environment name i got my flow name and finally i got my run good man this takes error handling to the next level because now forget about waiting for emails forget about even waiting at all like anytime a flow runs instantly now i know about it and and not only that right we could have done that before but now i can go click in directly to that run and deal with that exact instance of the issue exactly no need to search no need to find no need to loop through all your flow runs and that's not required and this could also be maintained in my system of record right whenever a flow runs and does something take an example of an approval workflow i can store this run information in my data source and then whenever i would like to see what has happened or what has taken place and just click on it will directly take the floor run so pretty useful very useful various opens up a lot of possibilities nice one man and i'll tell you the follow-up question to this from all our viewers reza we need this expression so we'll make sure we have this expression the description of this video so i'll make sure you have this so grab this and just use this all right i was i was gonna say i know that we were gonna get that question where can i get this expression yeah good good good all right moving on uh scenario number two uh i am a very uh heavy um participant or a very uh someone who promotes the forums a lot i believe in the community forums a lot because that's where i started my journey and whenever i go to the forums uh and i look at the flow forums i look at the questions being asked many times the questions are around you know i'm having this issue with that issue the one common thing that i see is when folks post the images or screenshots of their flows you know talking about an issue the first thing i notice on the top is there are like variables variables variables i see like tons of variables and then the flow begins right because we are initializing these variables to store certain information through their flows which makes complete sense it's not wrong you're doing the right thing but but when you create so many variables right in this case i have a variable for name and my variable name says john the title that's john's title company john works for years of experience expertise which is an array of information these are all independent variables and it is fine to use them it's fine to create them and work through your flows now the key thing to understand is that this is this concept has come in very recently every flow is going to get something known as a performance profile and i'm showing the actual documentation right here on docs.microsoft.com so something known as performance profile and performance profile basically sets how many limits sets the limits basically of your flow and the profile depends upon the license plan that you own so for example if you have the standard office licenses of a free license you are in the performance profile low state there is one that's medium low those are the premium plans then the dynamics plan so as you keep going higher in your licensing level your performance profile of your flow obviously keeps growing now what does the performance profile limit me to it limits you to the number of actions actions that a flow can take overall in a 24 hour period now it is not just for the flow it is for all the flows all the apps and any actions you take against the common data service or date overs in a 24 hour period now who's uh the performance profile goes against whose account well the creator of the flow the owner of the flow whatever license that user has would be the performance profile of the flow would be related to that and at the same time if you go to the request limits and allocations this is very important to understand for everyone right here is we have limits on how many api calls can we make in a 24 hour period and this is not just for flow this is for flow power apps and also cds so based on your license you have a certain set of actions that you can take now in flow and hear me out clearly inflow every step that you add right every action even initializing a variable or setting a variable or running a for loop everything is counted as an api call everything so in this example that i'm showcasing right here the trigger is an api call this variable is an api call so that's 2 3 4 five six and keeps going now if i run a for loop just imagine a for loop where i'm setting all of these variables and maybe i'm running a for loop that runs 50 times and i'm setting these 10 variables example 50 times that's 500 api calls gone in one floor so it's important to be aware of the limits and it's very important to ensure that you build your flows efficiently yeah now that i've kind of set the procedure for this one let me say one thing let me say one thing that i'm glad that it was you who went through all of that and not me so thank you and uh and number two i want you guys to know out there um don't fear these api calls there is some leeway uh we on the power automate team you know we only uh you're only you only get in trouble if you go over your limit by a very large amount if you are going over a little bit at a time or if there's a mistake made fear not nothing's going to happen the team is very flexible on things like that and so they this can sound very scary it is great information to know but also know there's a little bit of flexibility in it as well can i can i add something else so organizations create service accounts to run flows why because they want to go around licensing right they create one service account and they say yeah i'm going to run all my flows with the service account well guess what you got to think about it now and and of course john's there and you can go above the limits but it's important to note these things we are not scaring you guys but we are making you aware absolutely all right so here's an example wherein i have so many variables that i have created but can i avoid creating so many variables in my flow and the answer is yes there is a variable of type object okay and in this the object notation is nothing but javascript object notation which is plain simple json so right here if you look at my json and this might look a little small so i have this editor experience open right here i can zoom in so i have a very simple json that i've built right here which has the attributes name title company years of experience and expertise and for these i have defined the values as well so basically key value pairs and expertise is an array of information and all of these were actually individual individual variables that i had created earlier of different types like john variable name is john the type of string well i replaced it with one single json object which has an attribute name and the value is john simple so instead of creating so many variables i've just created one simple variable which is my profile variable let's say and that has all those values embedded right there great that's one way of saving api calls by reducing your variables well that's easy but now how do i grab the values from here what if i want to i want the value and i want to uh change the value i want to print the value i want to send it in an email you want to do many things with your variables right and variables have very simple actions to do that now in case of json there is one action which is called parse json and all you have to do literally for this action and i'll create this action from scratch all you have to do here is provide the content which would be nothing but the variable profile that i have created so i'm just going to create my variable here and for the schema just go to generate from sample and paste the data that you have and click done and just like that it goes ahead and creates this structure which allows me to parse the json basically pass the variable now if i go ahead and let's say i add a compose action if i want any of those values the parse json action is giving me everything here's the name the title the company the years of experience and these are all values in the json right nice so it's there easy but this is reza we want to save even this uh action why do we call even this action right i want to save one more api call so how can we go about even saving this api call not even calling parse json well for that what we could use is once again expressions so right here just to go ahead and show you what the expression looks like i will show a couple of simple cases the first one is let's say i would like to showcase i would like to showcase the value coming from the name property and for that all i have to do literally is this okay variables because i created a variable the name of that variable which is var profile question mark in brackets name now what is name name is nothing but this property for which i need the value for if i need title all i have to do is just replace the name with title if i go ahead and test this flow and just to prove my point once this flow runs it will grab the title which is power platform evangelist from this variable of type object that i just created so this flow is running right now ignore the error at the end uh right here we have the compose action and here is the value which is power platform evangelist so i don't need parse json to pass through my json i can literally go through and just grab the information by just using this very simple expression which is the name of my variable and then passing through the values of that variable now if you want to learn more about json parsing that was the first thing we covered in chapter three so this thing is is an addition to that but in the context of variables now let's say i would like to enhance this further let's say i would like to update this variable value right i would like to change the title so john you are a power automated evangelist you're not a power platform evangelist so how do i change the value of my variable or how do i set my variable well there's something known as set property okay there is a expression function called set property it requires the object which is nothing but variables my variable that i created and then it requires the name of the column that you're trying to update in my case it's the title column and then finally it is expecting the value and in my case the value is going to be power automate guru how about this junk something different i'll take that all right so now all i'm trying to do here is i'm saying i want to set a property in this object which is nothing but my variable and what am i trying to change which property value am i trying to change i'm trying to change the title right and what am i trying to change it to to power automate guru now if i go ahead and let's just remove this last action because looks like there's some error in it i was just testing prior to this call let's go ahead and run this flow and let's see how the value in that variable gets updated so the flow runs and here is the output json i'm just going to copy this and head over straight to my json experience paste it right here and guess what john is now a power automate guru so i changed the value of one of the properties in that single object variable that i created and i can do the same thing for anything else right what are the different variable types boolean i can set booleans true false right uh number values you want to increment decrement i can use the add function so i can add one or subtract one by using add n minus one so anything that you can do with variables is all possible using this technique and the beauty of this technique is that we do not have to use multiple variables a single variable suffices for all the variables that we want to create as part of our flow and that's how we can save our crucial and valuable api calls it's a nice one man that's a really nice one it's uh i yeah i i've never really even thought about it like that i'm guilty right a lot of my flows have a bunch of variables at the top i never thought to really just make it an array and then just pick pick what i need out of it exactly it's beautiful it's really nice thank you and now moving ahead to part number three now part number three the final part for today is around error handling okay error handling and flows and this is one of the most common common use cases that every flowmaker needs to be aware of is error handling because in flow by design or by default there is no feature of error handling all flow does is sends your notification that your flows have failed and your flows have failed x number of times in the last 24 hours now for this i will create the flow from scratch just to show you what are the different steps here in which i'm performing my error handling so i'm going to create a very simple flow that triggers manually and of course i will start with initializing a variable i'm going to call this variable once again the same case as before my variable profile and i will make this an object i am going to copy my value and paste it right here so i have basically initialized my variable right here of type profile now the key thing to understand here is that how do i go about performing error handling in case i take certain actions that could potentially result in an error reza why would flow through an error many reasons right when the flow is running maybe you're performing some action that is just not valid you're trying to divide by zero maybe you're trying to connect to a data source that is currently not available maybe you're trying to read data from a specific table from a specific column and someone just deleted the column it's all possible there are many scenarios wherein a flow could potentially fail now in this case i've just created my variable and the next step is i'm going to add a very simple compose action right here a very simple compose action and as part of this compose action i'm going to plug in an expression and this expression ties into the previous example that i provided i'm trying to set this time the expertise which is an array variable right right here expertise is an array and john has apps automate and power bi as his expertise in this case i would like to add one additional expertise maybe i'll give power virtual agents as well okay i'm trying better i'm better at pva than i am at apps in all fairness all right this case while i'm performing this i have purposefully made a mistake right so when i was creating this this variable that i'm trying to create right here or i'm trying to refer right here there is a variable called where profile but within this i'm trying to read a node which is v expertise and guess what if you look at my object it's called expertise it's not called v expertise right so i made a mistake it's possible right i'm building a flow i might write certain expressions it could result in an error many other use cases so i'm making a mistake here now if i go ahead and save this flow and if i go ahead and run this flow all right flow saving let's go ahead and run this flow okay the flow runs and guess what the flow fails because i'm trying to refer something that is null very common error message when when we try and perform certain actions on values that are null now how do i go about handling this error and guess what a flow can have multiple actions right i can even have another action after this that says you know what i want to set the variable as well maybe that variable at the start that i created i want to go ahead and set that variable maybe i want to send an email i want to do so many more things as part of my flow now how do i handle my errors because the flow is just going to throw an error not tell me what the error is where the error has occurred and which action how do i grab all that information well here's the trick in flows you can handle a group of actions together and do error handling together and the way you can do that is one of the actions and flow is called scope many people use scopes for grouping actions and you know cleaning their flows basically making their flows look smaller better but scope has a lot of other use cases here's one if i group the actions together and let's say i renamed this to like a try block classic uh dotnet kind of you know classic experience of development try catch finally and after this i will create another scope and in this i'm going to make this my catch block okay and this is where i'm going to catch exceptions any exception that occurs where that occurs in the try block and for that i will go here for this action my catch block go to configure run after and specify that i would like this cache block to run only when anything in that try block has failed okay that's the beauty of using scopes anything in there fails it will catch it okay and once i click done now i get this little red arrow right here indicating that this section of this block gets called only when anything in this block fails right and right here i can go ahead and this is what we typically i see people you know performing at a handling try catch they send a notification email but that's not what i want i guess i want a notification email but i want the actual error message how do i grab that how do i get the actual error the text which action in that try block field so once again expressions to the rescue if i head over to the function right here there is something known as result okay result the function called result and as part of this function if you go ahead and just pass just pass the name of that scope so in my case my scope was called i believe try this is case sensitive so result of try that's all i'm doing right now okay let me go ahead and run this and see what happens on the floor remember we are still building the flow we are not complete with this flow so i'm going ahead and running this flow and as you can see the action failed but this time i had a catch block that's going to handle that error so it's handling it but i just don't want to send a notification email i want to do a lot more now as part of this try if uh this compose action i use the expression called result and in result i just gave the name of my block which was try now let's look at what this result gives us it's very important to understand what it provides of course it provides json but not just json the try block has a lot of actions in it right i had a compose action and a set variable action imagine your scenario you have 20 50 actions in there it will return me each of the actions so here's my compose action it will tell me the status of each of those actions in this case the compose action failed it failed right why did it fail here's the error message this is what i want right this is what i want the maker of the flow or the user of the flow to understand that when this flow ran this was the error so i can grab the exact position i can grab the exact code and also grab the exact message that flow displays in the flow run only and that is right here and for the preceding actions for example set variable so you can see that action was skipped and why was that action skipped because my flow resulted in an error right here when i get an error the flow just stops processing further but because i handled it it's processing further and then this magic expression called result gets me everything that i need i didn't know about result either is it this is a master class an unknown unknown template language things today this is awesome thank you and now to show you my complete flow because i want to save time here here is my flow which has the entire error handling piece and i'll show you how i'm using result here as well it's the same concept basically here's my flow triggers manually i have my try block i have that same error that i'm producing here and i have an extra action and here's my catch block now comes the magic right here i'm using that same result expression nothing special a result of the name of my block now next step if you notice the json it returns an array but i am only interested in the actions that have failed so for that i have to filter the array and filter on what filter on the status equal to field so how do i go about doing that for that all i did is this i used the data operation called filter array and for this i provided that same result expression which gives me the array and in there i'm checking to see if the status and this is also an expression item question mark status we showed this in chapter three it's that same expression right here i'm grabbing the status and getting the statuses where it is equal to failed because that's what i'm interested in next i select again this is a data operation from this array i just select the error code and the error message i am not interested in all the other data that is provided right here i just want the code and the message so for that i have used the select data operation and then i'm just using the create html table action passing this operation here and sending myself an email and in this i'm also having that same function i showed you in the first scenario which is the link to my flow run because the user can directly go to the flow run so this is an amalgamation of everything that i just showed you throughout the session so let's go ahead and run the flow you make it look so easy man it's crazy and when i watch you i'm like this is so easy and then i go try and do it and i'm like this is not as easy as he makes it look samples and guess what because these flows that i'm creating have no connectors i'm not connecting to any data source i'll share all the flows as well so you can see it live nice nice that was one reason why i didn't use the connectors okay so so here's the flow the flow ran error handling has happened great and of course if i go to the flow runs this is what this is all i see right i see success success because i've handled the error yep but here is the email that i received and check this email out i'm gonna try and zoom in yes right this is a nicely formatted email it tells me that there was an error in my flow run and i can have all the details here which item the flow was running on or which document or which record whatever your use cases right this is the error code and this is the exact error message that flow throws right here and to tie all of this up together why should the user even go and search for the floor on here's a link with a little bit of a smart emoji right there to take me directly to the floor run so if i select this guess where it's going to take me directly to that flow run experience direct right drop my microphone my goodness that's it you see how simple it can you can simplify things by knowing expressions and what were the expressions we used workflow to give me the run details result to give me the result of a block so i can scan through the json and that's why expression language understanding is so important because to pass through these things yes i can use parts json but why why do i add additional actions why not save api calls why not reduce variables why not use json and that was just it's so much easier and cleaner too right than having to to try and parse on spaces or parse on certain words and right this just sets everything up in such a nice manner it makes it all selectable and i like how you still you select and then send an html table that's just such a nice nice little like what is it a feather in the cap or you know it's just it's not such a nice added touch so here's the follow-up question from the audience how did you format that html table well i'll share the entire flow so you can grab all the information awesome you know what reza you know what you should do uh big idea here you should make a blog post maybe that has all these expressions in it and uh and then i could link that in the description so they have one handy place to go links over to your property so they can see all your wonderful stuff once they're done checking this out let's let's get them over to my home yeah let's do that absolutely absolutely so you guys at home here's what you do you go down and you check the description there's going to be some links for raza there there's going to be a link to a post that'll show you all of what he showed today these expressions so you can use them a download to the flows but more than that go ahead and get connected with him follow him on twitter go ahead and subscribe to him here on youtube he's on my channel today but he does stuff like this all the time on his own channel so it's definitely worth going and getting subscribed over there because as you can see he's a genius he's showing me stuff that i've never even heard of before so definitely something you want to do man thanks so much for coming and hanging out like really appreciate you coming here every time and and giving us a master class thank you thank you for giving me the opportunity to come here and and present this stuff and and if if the people speak and they say we want another expression series we'll come with more i like that okay so you heard the man demand more all right okay you guys go ahead and click like click subscribe so that you don't miss another video go in the description get connected with raza but for now that is it from us we will see you in the next one much love take care later
Info
Channel: Jon Levesque
Views: 3,497
Rating: 5 out of 5
Keywords: jon levesque, jon levesque microsoft, power automate expressions reference, microsoft power automate expressions, jon levesque microsoft flow, microsoft flow expressions, learning expressions, expressions power automate, expressions microsoft flow, expressions intro, introduction to expressions in power automate, introduction to expressions microsoft flow, expressions, WDL, workflow definition language, logic apps, logic apps expressions, functions, power automate expressions
Id: TCIr7Bc3Oko
Channel Id: undefined
Length: 36min 11sec (2171 seconds)
Published: Tue Feb 16 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.