ChatGPT wrote a Python script to solve my Power Automate problem!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's going on everybody Daniel Lemay here welcome back to doing it with AI and today we're going to be talking about python power automate chat GPT HTML I'm just throwing all the acronyms at you today but this is really cool so stay tuned you're not going to want to miss this [Music] all right so as you know this channel is all about how can we integrate AI in our daily workflows how can we make life easier for ourselves by letting the machines do a lot of the work and this is a perfect real world example that I'm about to show you so a while back I needed to prove out a concept I need to be able to create a calendar entry based on some data that was coming from an external API and I wanted to use a cloudflow to do this in power automate and I had a web hook that was going to be sending a payload over to my power automate cloudflow I had an HTTP request receive trigger and I needed to parse that Json get some dates out of it and then create some calendar entries in exchange and that all seems pretty straightforward until you take into consideration time zones anybody who's built anything with time or time zones knows it can be a real pain and the data that was coming out of the payload from the web hook did not match up with the out of the Box actions for power automate to create some calendar entries so I needed to figure out how to transform the string that was coming out of the payload to make it match what was coming out of the action in power automate so instead of trying to figure out a way to do this with string manipulation and flow Expressions I decided to throw this problem at chat GPT and see if it could do it for me and the solution that it came up with was pretty amazing let's dive in and take a look so I feel like the best way to kind of explain to you how I went through the thought process of building the solution and using chat GPT to kind of help me figure out a problem is to relive that experience with you and go ahead and build the flow from scratch we'll uh we'll integrate with Postman to make some calls we'll use vs code to kind of manipulate some information and then you'll really understand exactly what I went through to figure this out so I've started a new flow here and I'm going to search for a trigger I know what I want it's the HTTP request trigger there it is when an HTTP request is received so I'm gonna go ahead and pick that now I can't show you the actual request body Json schema this was a proof of concept for a client of powerapps 9-1-1 and there was some sensitive information in there and so I'm gonna have to generate my own sample payload to define the schema for this uh for this trigger so I'm going to make an array and I'm going to put a record in here and I'm going to have a key value pair where the key is called time and it's going to produce a date string but in our case I don't want to type out a whole date string so I'm just going to write the word string which is going to have the same effect so I'll hit done and you can see there it's the type of array and inside there we have some items with the properties of time and time is a string data type so that's going to work for us we're going to go ahead and create a new step one of the things I like to do when I'm building out flows especially if I'm trying to pull some data out of a Json that's coming into the flow is to put a compose action right after the trigger and that will allow me to kind of drill into the data to find the specific key value pair or you know array or object or whatever it is I'm trying to get and just bring it into the compose to kind of Silo it away from the rest of the noise and I can figure out exactly what I want so because I've defined this request body schema as an array I I can't use this time Dynamic content now we know that time is the value that we want to get out but we can't use this because if I click this I'm going to go ahead and do it and show you what happens right if I click it it creates an apply to each why does it do that because it's an array so flow is trying to be helpful it's saying oh I know that you know the the request body is producing an array and you want the time value while there's going to be multiple time values potentially so I'm going to go ahead and try and apply this action to each of those we don't need that we don't need to do that so what I'm going to do is kind of get that time Dynamic content out of there drag this compose out and go ahead and get rid of the apply to each and instead here I'm going to create my own expression so I'm going to take the body so this is going to give us that array of time values and I'm going to copy this throw it over in the expression section here and I'm going to drill down into it but I know there's only ever going to be one record because I'm I'm going to be the one sending the payload and so I'm going to only ever send one record so I'm going to drill into that first record by putting a question mark and then a zero inside these square brackets which lets me uh say I specifically want the first item in that array and I'll put another question mark and then I'm going to say I want the time value out of that so we'll hit OK and now we have our compose action so now I'm going to go ahead and click save and of course this doesn't really do anything except extract that value that I want so that I can validate that that's actually what I'm wanting to work with and if we go back to our trigger we can see we actually have a post URL now which is going to be super helpful because we're about to switch over to postman so that we can copy this URL which I'll just click this little button to do and we're going to make a post to that URL from Postman and see what happens so let's go over to postman and take a look all right so here we are on Postman now if you don't know about Postman um there's a bunch of great YouTube videos about how to use Postman I'm not going to go into that in this video it's a really robust app for testing apis making API calls creating collections uh where you can you know have a whole bunch of different methods and different endpoints to find for a single you know web service again huge topic I'm not going to go into it right now so what I am going to do though is just use it to do a quick post to that URL that we copied earlier in the video so I'm gonna create a new request and I can do that by just coming up here to this plus sign and then it creates a new Untitled request as you can see there so I'm going to say I want to do a post I'm gonna put in that URL that I uh copied from our trigger in power automate so you can see it pulls some parameters out of here that's fine it's reading those from the URL itself we're going to leave that alone and then I'm gonna go over here to the body section and I'm going to do raw and the raw body that I want to put in is the same as the sample payload except this time I'm not going to just put in string right time is equal to string I'm going to put in time and then I'm going to put in an actual string value which is the date stream that I want to use for the rest of this demo so that string is shaped like this year month day time and then time zone so in this case it's plus 11 UTC so that's the string I'm going to pass in we've got it set to Raw here let's try it out and hit send okay it said 202 accepted is the status so the request has been accepted for processing let's jump back over to the flow and see if it actually worked so here we are on the flow again and you know I've done this a few times I have a suspicion that my compose action may not produce the result that I want and so what I think I'm going to do is throw in one of my favorite actions of all time in power automate and that's called parse Json and what I'm going to do is for the content parameter for parse Json I'm going to tell it I want to use the body so I'm going to use the trigger body that comes out that's our payload from when the request is received and then for the schema well we know what the schema looks like it actually looks just like this so I'm going to copy the schema from the trigger and paste it in here then down here in the compose instead of using the trigger body I think what I'm going to do is I'm going to come down here and look if you notice time is now available in the parse Json action I'm going to use the body from parse Json I'm going to copy that and use that for my expression why am I doing this just experience I've done this a few times uh and you know it just seems to be more consistent what I like to do is I like to use more actions that I need initially when I'm building my flows and then I kind of uh shrink those down to you know the minimum actions required and make the flow as efficient as possible later once I have everything working the way I want so we're going to do the same thing we're going to pick that first array element and we're going to pick the time value out of it I'm gonna hit OK I'm gonna hit save and then what I'm going to do is go to test and I'm going to hit manually and I'm going to hit test so let's really quick switch back over to postman and then let's go ahead and hit send again all right it's sent let's go back to Power automate and let's see what happens okay it was successful so it worked we were able to parse that Json from the trigger you can see there there's our time value the string that we put in and there is the actual date time value that we got out so now that that's done we know that we can send a payload to the flow let's go ahead and keep building this flow out a little bit I'm going to edit the flow I'm going to add a new step and the action that I needed to use was to create an event in Outlook in exchange so if I add an operation here I can pick the create event V4 action I'm just going to play around with this I'm going to add it to my own calendar I've got access to a few people's calendars here but I'm going to add it to my own the subject is going to be uh chat GPT rocks and then the start time we want to use Let's see we want to use everything except that UTC value see it shows us that there's an example right there is an example of the kind of time that it wants to bring in so we could just go in and say yeah we want to do you know the time value from parse Json again it's wanting to since I picked that time value it's wanting to create and apply to each but we don't want that let me get rid of that bring it up here get rid of the apply to each what I actually want is the outputs of the compose and then let's say I want the end time to be like 30 minutes later right so what I'm going to do is write an expression for that so I'm going to put the end time in there that gives me uh the again the outputs of my compose which you remember is the time value that we sent in from our our payload and I'm going to go ahead and copy the in time and write a quick expression and with date and time I know I just want to add 30 minutes to that start time so I'm going to come down and see my add minutes here I'm gonna pick add minutes I'm going to paste in the outputs of my compose which is the same as the start time in this case and I'm going to put a comma and then I want to say I want to add 30 minutes and hit okay so that should add 30 minutes to my start time now here's where we get to the interesting part the time zone so we know that the end of our daytime string has this plus 11 colon 0 0 on it well that is the actual time zone that it wants but just because it has that on there doesn't mean that the start time and end time are going to respect that time zone and in fact what we have here is a time zone parameter that has to be set it's a required field for this particular action so let's just take a look at what's available we've got a long list of things that are available here there's a lot of duplicates in here and you know it's just it the list is it's not available online I went to Google I tried to type in you know create event V4 give me a list of all the time zones I couldn't find what I needed so what I did was I knew it was plus 11. so I came down and I looked for UTC Plus 11. and I found all these different options there's one two three four what is there five different six different plus elevens well if as far as I'm concerned it doesn't really matter whether it's you know magadon or Norfolk Island they're both plus 11. I don't know what the difference is uh we're not going to go to through that in this video so I just chose magadon right but here's the thing this is a global company I was doing this POC for so it's possible that plus 11 is not always the time zone that's going to be used so how are we going to handle that well there's a really interesting thing we can do here so let's go up above our create event and let's do a little bit of manipulation of this and we know that our time stream is shaped like this year month day time and time zone so we can do some string manipulation against this to just split this piece off I was going to add another compose action I think I will do that actually let's add another compose action and let's take the outputs of our previous compose and what I want to do is I want to split that time zone piece off of the time itself the date and time itself so what I'm going to do is say split I'm going to put in the outputs of my compose so again this the date time string that comes from our payload and this time I want to split on the plus sign okay now what that's going to do is create an array and if there were multiple plus signs in that string then we would have you know more than two records in our array but there's only one plus sign in that string so we're going to have two records in the output of this split and I know that I want the last one why do I know that because when you split that string in half the first part is going to be the date and the time the second part is going to be the time zone so I'm going to say last split outputs compose and we're going to split on that plus sign and that's going to be my oh I missed a parenthesis there but that's going to be my expression so before we come in and create our event now let's just add a terminate in here because we want to check and see did what we just do actually worked did that split work the way that we think it was going to terminate allows us to kind of stop the flow in its tracks and anything below that terminating action is not going to run so I like to use this a lot to kind of Stop close do some checking and then continue on let's run a quick test okay time zones required let's just go set any old thing I don't know -11 doesn't matter it's not going to run anyway flow why are you bothering me with that okay so we're going to run a test here all right we ran successfully let's see what compose two looks like all right interesting so it looks like this we have 11. so in our case we split on the plus sign now what are some other ways we can consider doing that well uh we could count the number of uh characters and split after a certain number of characters um that would work there's probably a handful of ways that we could handle that so let's take a look at one of the other ways because you know it's 11 is great but there's the potential there that maybe it's negative 11 which is what we had set for uh the creative inaction down here which is coordinated universal time negative 11. that's not the same as positive 11. in fact it's the opposite so let's see what some other options are so we've got this compose action right and what we did originally was we said we wanted to split on the plus sign well that would you know that work sort of but it doesn't give us the plus 11 that we need it just gave us 11. so let's see what else is available if we look at our Expressions when you look down through here in here somewhere there's going to be something called slice I believe it's in the string functions there it is slice returns a section of a string defined by the start index and if you want an ending index well what does that mean it means the number of characters uh from the beginning of the string uh to whatever we want before we want to start slicing the thing up so what I'm going to do is I'm going to type this back out again we know it was year month day time you know 8 A.M 8 30. Plus 11. so what I'm going to do now is just look at this for a second I believe that's 19 characters so what slice is going to let us do is it's going to let us say hey after the 19th character I want whatever's left because we're not going to Define an ending index so for this expression I'm going to delete this for this last expression I'm actually going to switch that to be a splash not splice but slice I'm gonna get rid of my split and then I'm going to come over here where my plus sign is get rid of that last parentheses and I'm going to put in 19. double check your spelling people I can't spell half the time so put puts is definitely not going to work let's go with outputs all right slice outputs compose comma 19. update and let's get rid of our first one here let's go ahead and run and test on that let's see if that worked okay it ran successfully and there we go now our compose is showing what we want plus 11. okay so that works pretty well right so from this point What's Next what are we going to do from here well what we need to be able to do is Define a custom value for this time zone parameter and if you scroll down to the very very bottom it'll say in our custom value and that will allow you to type in a custom value but the problem and what I discovered is that the custom value actually has to match up to B one of these values from this list and like I said before this list is not available at least I couldn't find it maybe it's available somewhere if it is you know leave me a comment down below let everybody knows it would make life a lot easier but what I did instead was I said well how am I going to solve this what I need to be able to do let me go ahead and delete this terminate what I need to be able to do is say based on what the output of this compose number two here is this slice expression that we just wrote I need to be able to set a custom value for the time zone but I don't want to have to write all of these things down and then write a crazy expression which would look through those things and figure out you know what does plus 11 equal and it could be any of these that are down here if we scroll down again down to plus 11 it could be any of these I don't really care as long as one of them is selected so how would we do that well I started thinking about it and I thought the best way to do that would be to create another compose action or maybe a variable and create an array and have an array of all of these options and then filter that array based on the output of compose number two the output of this slice that we just did and what that would let us do is say if one of these values here contains plus 11 then just give me the first one I don't care right uh boo game will oh and I probably butchered that sorry uh Bougainville Island I don't care what it is as long as it's plus 11 right the problem is this is a really really long list so how did I solve it well this is where chat GPT comes in so I started thinking about it and I said I bet that this is in the HTML of this web page somewhere so could I extract this table of data to very quickly create a new array that I could then filter based on that plus 11 value Well turns out I can and so let's take a second and walk through it's going to be more than a second let's be honest let's take a few minutes and walk through how I did that so if you're using Chrome like I am you have access to something called developer tools and I know this exists in Firefox it probably exists in Opera I know it exists in Edge since it's a chromium-based browser just like Chrome is um and so uh what the developer tools does is it gives you access to a whole bunch of information about what's going on behind the scenes in your browser so this would be information like the code itself that's that's being run to show you these websites that you're looking at Network traffic and information performance right how much RAM is being consumed all those sorts of things all that information is available in developer tools and a lot of it's not going to really be useful unless you're like you know a developer and you're actually building websites you're a pro code developer that's not me but what I use it for is to see network traffic and code and so what I did here is I said I bet I could use developer tools to look inside this list and actually get the HTML that's behind the scenes that enumerates this list and then pull that into something like vs code a code editor and maybe do some manipulation with it maybe I can create my array out of that so that's what I'm going to show you how to do real quick so uh you can either go up here to this ellipsis in the top right hand corner hit that and then go to more tools and developer tools which isn't showing up when I try to record it or you can do what I like which is shortcut keys and do Ctrl shift I which is going to open up the developer tools for you so what you want to do is you want to be on this elements Tab and elements is going to show you the actual code that's happening on the page that you're currently looking at and it's kind of interesting I have you you can expand these different elements and look into them and as you kind of move across the code it starts highlighting stuff on the screen but because modern websites are so complex this isn't going to give you a whole bunch of information right off the bat right so what you want to do is go up here to this little icon that has a kind of like a cursor and a square and it's it's an element selector so if you click that what happens then is that as you hover over things on the website that you're looking at you're going to see those things reflected in the elements window to the right so you're going to be able to start seeing the code behind the scenes that's really useful that's exactly what we want so if we come down here to our create event V4 action and we hover over our drop down here we can start to see some things so we over on the right we look let me go ahead and click on this and what happens is it kind of sticks on one thing so this is a div element this doesn't really tell me anything in fact it's it's a little bit obfuscated I can't really see what's going on over there I certainly know that the list of things that I want to get out of there the time zones isn't there so I'm just going to go ahead and expand this out because I have a feeling that down in here somewhere is going to be the information that I want so nested inside that div is a span I'm going to expand that out yeah you know I still don't see what I want so where could this be well I'm going to start just kind of looking down through these things so I've got a bunch of divs down here and notice that as I'm kind of moving down on the right hand side I'm still hovering over the time zone drop down so as I go through all this we're still inside that parent div that's controlling that drop down and what I like to do is look at the names of these controls and it gives you some context if it's a well-coded website it gives you some context as to what you're looking at I mean this is a combo box right that's good that's good to know so maybe I need to expand this time zone drop down let me hit that does that change anything it does look some new div class appeared over here and in fact it has an aria label so you know a label for with the Aria font called time zone interesting so let's expand that out a little bit okay now we have another div class msla combobox options enums okay enumeration that seems like that could be the ticket so let's expand that out a little further because I still don't see a list in there I do see enter custom value but I don't see a list of all the time zones like I'm seeing in the drop down so let's expand that out okay now we have an ol class still no list expand that out and okay now now we're starting to see some stuff that looks really good so if we look in here as we hover over these things notice on the left there in the drop down how it's hovering over the different uh options in the drop down and in fact if you look inside of each of these Aid elements you're going to see the Aria label is equal to the string that we actually want to extract so this is really useful so okay we know that this particular ol element has what we need how do we get this out of there well what's really cool about developer tools is for any of these elements that you're inspecting you can right click on them and hit edit as HTML so you can't see this on your screen but if what I'm doing here is right clicking I get a list of things here and one of them is edit as HTML so I'm going to click that and what it does is it brings up all of that ol class uh information that I was just looking at in HTML in this scroll box so then I can pull this out which is really cool and if I can get that HTML out then there's a good chance I can do some modification some string manipulation against it right so I am going to just click in here somewhere do a control a and Ctrl C and then what I like to do here is go over to a text editor now you could use notepad plus plus you could use Visual Studio I really like vs code because it's free and it handles basically every programming language I've ever heard of so that's what I'm going to switch to and what I'm going to do is take what I just copied and throw it over into vs code and what it will format this for us so that we can get a better look at what we're what we're dealing with here and then we'll take another step further so let's pop over to vs code real quick all right so here we are in vs code if you're not familiar with vs code just like with Postman there's a million YouTube videos go check one out vs code is awesome I've been trying to convince my colleagues to use vs code for a really long time it's just a great text editing tool it can do comparisons it has a bunch of extensions in the common services that you probably already use and if you're a developer then it's just a great all alternative to paying for a visual studio license if you don't have one anyway I'm going to go up to file and I'm going to do a new text file notice it says select the language I know what I'm about to put in it's HTML but there is also this option to Auto detect so I can put HTML in here down here in the right hand corner it tells us what our language mode is my guess is that it's going to understand its HTML so I'm just going to paste it and see what happens notice HTML it figured it out so if it understands what language it's dealing with then a lot of times it can actually format the text that you paste in because if you notice we've just got this massive string here all on one line and it's it's even less readable than it was over there in Chrome so what I'm going to do is I'm going to right click and hit format document and boom it formats it for us so this makes it a little bit more readable and even more exciting than that if we look in here we start to see all of these values that we were looking to pull out in the first place when I was figuring this out myself I made it to this point and I went hmm okay so what can I do here I don't really know what I was going to do but I did know that Python and other scripting languages are really really good at extracting uh you know values from giant strings and so what I did was I took a look at what these things were where they lived and it turns out that they all live inside of span elements so we look at this one UTC plus two which is Jerusalem we can see that it lives inside of some span tags okay and I got to looking at the code a little bit more and I realized that basically the only span tags in this entire ol class element or object is populated with one of these UTC values that I was trying to extract and so I thought to myself hmm you know what I should do is just go over to chat GPT and see if it can write me a script of some kind that could extract these values from the span tags without me having to figure out a way to do it myself so let's take a look at how that worked let's switch over to chat DBT okay here we are at chat GPT so what I did for this point was I decided I'm just going to ask chat GPT to do the thing that you know I would have to figure out how to do myself so what I did was I said okay what is the problem I'm trying to solve well the problem I'm trying to solve is I need to extract values from span tags in that big ol class element that we had pulled out of uh the power automate web page so what I did was I went over to chat GPT and I just gave it a really specific set of instructions so I said something like show me only the values that appear in span tags from the HTML held in a variable called code and represent those values in a Json array as records with the following shape and then I defined a shape and I said TZ which is time zone of course and then I gave it this value which was called span value which I didn't know if it would understand that or not but that's what I gave it um and then I just hit enter and so here it goes right here's the power of Chad gbt in action so it's gonna import a module our library in this case probably called Beautiful soup and then uh it says okay soup equals beautiful soup code html.parser soup dot find all span span values TZ span.txt for Span in Span so this is a loop before I'll Loop right here and then Json data equals json.dumps span values and then print that out interesting so what do you do with this at this point well you pop back over to vs code and you see if it works so I'm going to hit copy code and I'm going to switch back over to vs code so here I am back on vs code and I've got my HTML that's still showing up here but I need to create a new file that's going to hold my python script that chat GPT just wrote for me so I'm going to hit new text file and uh just like last time you know what I'm gonna let it see if we can figure out what language I'm using just out of curiosity so I'm going to paste in well that's not what I want is it I had thought that I copied that there it is so I'm going to paste that in and you know it didn't pick it up but it's probably because I pasted HTML in there first so I'm going to come down here and select my language mode and go and find python I could type it in up here too Python and now what I have is I have my code but I need to make some modifications to it this is a really important thing to understand about chat GPT it's not going to do everything for you it's not going to do your job for you it's not going to write every single script for you in its entirety most likely you're going to have to make some modifications and in my case I told chat GPT that I wanted to have a variable which held my HTML code for it to process and I wanted that variable to be called code so what I'm going to do is edit my script I'm going to come in and I'm going to Define another variable here called code and by the way if I didn't know how to do this like if I didn't know how to define a variable in Python then I would just go back to chat GPD and say how do I Define a variable in Python and it would explain that to me and here's another really good example right so code I know it should be the HTML from my other file over here this one right so I'm going to go ahead and copy this I'm going to paste it in and this isn't going to work because we have some red lines in here intellisense is seeing all these issues you can see this big red bar along the side it's not going to work because code should be a string and in Python when you want to define a string in a variable like this you need to wrap it in three double quotes again I know that because I've done this before but the last time that I did this I didn't know that and so I had to go to chat GPT and ask it how do I Define a string variable in Python and it told me that I need to wrap all of the string that I want to set in the variable in triple double quotes so I'm going to do that one two three I'm going to come down here to the bottom of this big uh HTML block right there and do one two three all right and so now everything looks happy intellisense is happy the red bar is gone from the side so now what I'm going to do is go up here to run and I'm going to hit run without debugging and what it's going to do is it's going to pop up and make me save the file so I'm going to go ahead and do that real quick you can't see that on your screen but it's uh there's nothing to it you just give the file a name and hit save so I'm going to call it import json.py which is a python file okay so it's telling me no module named bs4 okay well how would we handle this problem well we can hover over bs4 up here and see what it says it says uh could not be resolved from The Source report missing module Source okay fair enough why don't we switch back over to chat gbt and see what it says all right we're back on chat GPT so let's just ask it how do I import a the bs4 module and it's telling me you can import it uh that from beautiful soup okay alternatively you can import it using the following command import bs4 and then use it as bs4. beautiful soup before importing PS4 you have to make sure that the package is installed in your system you can install it by via pip by running pip install bs4 well let's switch back over and go to the terminal and see if we can make that happen so I'm here can I actually just type in PIP install bs4 hey okay well I mean did that work I don't know let's see what happened let's go back to Ron and hit run without debugging there you go right so hey this didn't actually happen to me last time so the last time I did this and this it's been a couple months uh chat GPT wrote the script a little bit differently just another thing to consider about chat gbt right it's not always going to write things exactly the same way nor does it remember what it wrote from a previous chat or even a chat that you had just done with it maybe earlier in the day it's not going to remember those things but what you have to understand is that if you just go back and you give it some more specificity maybe a little bit more uh direct about what you want uh it can really provide you with a bunch of different alternatives to solve the problem and in this case I didn't have the bs4 module installed so I went back to chat gbt and I asked it how can I install the module it gave me the answer I popped back over to vs code I typed in PIP install bs4 and it went out and installed it for me and as you can see after installing the module uh I went back to Ron and I hit run without debugging and looking at the terminal here the script ran successfully if I look down in here I actually have the output that I was looking for so if you know here is a Json representation of everything that was in this HTML but it's spelled out exactly like I want it so what I'm going to do is go in here and grab this array copy it create a new file yet again this time we're going to do Json but let's see if it can detect it paste it in okay it doesn't see it as Json so I'm going to come down here to the corner like we did last time go to plain text hit Json and there it formatted it so now I can hit right click format document and what a beautiful thing we now have Json so how can we use this well we need to go back to our flow and we need to use that old friend that we used earlier called parse Json and see what we can do with that um now I what I like to do is kind of look through this first right like uh there's some problems in here like look right here Hong Kong we have like an escape code and then this massive thing here um this could cause some issues so maybe what we need to do is clean that up a little bit one other great thing about um vs code is if you have a consistent problem like we do here if you highlight something it will show you all of the instances where that shows up and notice over here on the right hand side of the on the scroll bar you see all these little gray dots that's actually all the instances in which this uh forward slash in and this many spaces shows up so I can click through here and see all the different occurrences of where that is and even better than that what I can do is I can replace all these things at once so I know that this escape code it probably just needs to be a single space so what I'm going to do is highlight what I want to change right click and hit change all occurrences Ctrl F2 is the shortcut key if you want to do it that way once I click that I can simply hit backspace and then boom it says it the way that I want it really really powerful stuff so I'm gonna just do a quick check through here make sure everything looks decent because I'm about to take all this information and put it back over into our flow and it all looks pretty good so what I'm gonna do control a control C and then what I'd like to do from here is pop back over to our browser and look at our flow again so here we are we're back at our flow and what I'm going to do is close out the developer tools and I'm going to start working with what we have now so I have an array in my clipboard and it's the result of the chat GPT python script that we created so what I'm going to do is insert a new step and I'm going to just do a compose now I could do an array variable here that would work fine too but I'm just going to do a compose and I'm going to rename this I'm going to call it TZ array just so we know because we're starting it's starting to get confusing right you should really be renaming your actions as you go along but I have a bad habit of not doing that when I'm in a hurry I'm going to go ahead and paste in the output of our uh GPT created python script and so now you can see we have this big Json array in here and what I'm going to do is just kind of collapse that and create another action I'm going to use our old friend parse Json and the content of that is going to be the output of the TZ array right because I want to look to this I'm looking to get values out of there so I'm going to say parse that the schema I'm going to generate from a sample which is going to be exactly what I just posted it uh pasted into the compose or into the TZ compose action I'm going to hit done and you can see in here it read the schema TZ string it's exactly the same schema that we had for our uh well essentially this exactly the same schema that we had for our payload and the trigger uh with the with the exception that it's called TZ instead of time but anyway doesn't matter so now that we've parsed that well I want to rename that as well parse TZ array okay so what do we need to do right what was the problem we were originally trying to solve the problem we're trying to solve is we need to be able to filter that array so that we can create a custom value here in the create event action so there's a really handy action in power automate called filter array I'm going to type that in pick that the array that I want to filter is actually from the parse um when you parse a piece of Json in a parse Json action that actually is aware of the schema and subsequently when you use that in Downstream actions it becomes much easier to use filter queries against it so what I'm going to do is say I want the body of the parse TZ array and the value I want to choose I want to say right remember up here in compose two this is where we did our slice this produced plus 11. all right so what I want to do is I want to filter out the TZ array that chat GPT made for us with its python script and I want to only get back the values that have plus 11 in them so what I'm going to do is I'm going to come down here and I'm going to say uh I want to do a contains right because we have plus 11 and we know that that is a substring of our TZ values that we got back from the script from Chad GPT so what I'm going to do here is when I choose a value for filtering the array again we're filtering parse t z array I'm gonna say on a parse TZ array where t z is not equal to but contains and then the outputs from compose two which of course is our slice so this is our plus 11 right here right so one of the things you have to be really careful about when you're doing this is to make sure that number one you're comparing two of the same data types so if you're trying to do a filter array and you're comparing a string to a number for example that might not work and the other thing that you want to look at is to make sure that the the two values that you're comparing are the same and sometimes what you'll see with scenarios like this is that you have some like trailing spaces or something that can screw you up so one thing that I like to do to kind of prevent problems like that from happening is to come in here and do it one more uh piece of string manipulation against our outputs so if I go I know this is the composed to outputs I'm going to go back up here to my slice and I'm going to do two things first of all I'm going to wrap it in string the string function which turns a number or any other value that it can into a string and secondly I'm going to wrap it in trim and trim is going to take off any leading or trailing spaces or Carriage returns or anything like that that could screw up the comparison so I'm going to do that and hit update which that gives us a new expression up here for compose two a little bit more complicated not too crazy and of course our filter array is still using the the same outputs from composed to to compare against the TZ value so why don't we go ahead and run that and let's see what happens okay it says it ran successfully all right and compose three has uh Bougainville Island right um and apologies to the inhabitants of this island because I'm sure I am absolutely butchering that name anyway so we got the first value back again I don't care what plus 11 it is whether it's that or magadon or whatever the other ones work so as long as it's plus 11 I'm happy uh let's go ahead and edit the flow let's come down here get rid of our terminate action and then lastly let's go ahead and come to our time zone value for create event four and let's get rid of what's in there and let's go to enter custom value and I'm going to put the outputs from compose 3 because again this produced the right result we just saw it it gave us that plus 11 value that we were looking for and we know that it matches the time zone values that are available shouldn't be any errors because we pulled directly from the list that's there in the time zone parameter for create event V4 so we should be good to go so I'm going to go ahead and save this and then what I'd like to do I think is let's go back over to postman and see if we can create a calendar event for I don't know maybe a week from now what is today today's the 19th maybe the 26th right let's see if we can create a calendar event for the 26th all right so we're back over here at Postman and one thing I wanted to point out is that um you know when I saved the flow last time you probably didn't catch it and it may have gotten edited out of the video but one thing that you have to do uh if you're passing Json as a payload into a power automate Cloud flow where your trigger is expecting a Json payload you need to come over here to headers you need to make sure you have a content type header that defines the content that you're passing in as Json so I set a key of content Dash type and a value of application slash Json and what that does is in at least in Postman is it kind of changes the way that your body your raw body string looks it actually reads it as Json at that point so what I'm going to do is I've put in a new value here 2023 126 at 8 30 plus 11 UTC so I'm going to go ahead and send that of course I don't know what time that is in Eastern time but we're about to find out so I'm going to hit send and we've got a 202 accepted so that means that the flow should have run let's switch back to the flow take a look at that and if I go back here and go back to my flow we do have a successful run and it looks it looks a little strange um up here we have a start time of the 26 and an end time of the 25th which of course would be going back in time it doesn't really make sense but if we look down on the outputs we can see that it actually started at the 25th and 21 30 and 20 ended at 2200 so we have that 30 minute window we were looking for and you know there might need to be some slight modifications there so at the end of the day what I've been trying to get across to you here is that what I was able to do is use chat GPT to write a python script that I didn't know how to write myself and create value out of that right these other things I can troubleshoot I'm familiar with power automate I'm familiar with cloudflows I know about exchange and Outlook so those things are easy but stripping all that information out of the HTML that was something I never done before and it was something I didn't really know how to handle inflow in an easy way I would have been doing all kinds of crazy Expressions to try to get that information out and I didn't have to do that in this instance because I had chat GPT available so I know that was a lot of information but I hope you got something valuable out of it subscribe to the channel if you want to see more stuff like this I realize that we're probably going to be touching on some fairly complicated topics but I suspect a lot of you out there watching are in the tech industry and are interested in Ai and where we're going with this I really think we're at a very exciting time and to be dealing with these types of platforms so again I'm Daniel Lemay this has been doing it with AI and I hope to see you again soon take care thank you foreign
Info
Channel: Doing It With A.I.
Views: 2,459
Rating: undefined out of 5
Keywords: Power Automate, Cloud Flow, Outlook, Create Event, Postman, ChatGPT, Python, VS Code, Time Zone, String, Problem Solving, Demonstration, Tutorial, Power Platform, Microsoft, AI, Automation, Workflow, Integration, Business Process Automation, Office 365, Artificial Intelligence, Machine Learning, Productivity, Code, Programming, API, Time Zone Conversion, Microsoft Power Platform, PowerApps, Power BI, Microsoft Flow, Automation Tools, Business Solutions, Technology, @ShanesCows, PowerApps911
Id: QbChiGRT1EY
Channel Id: undefined
Length: 51min 26sec (3086 seconds)
Published: Mon Jan 23 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.