let's start with creating a flow that gets triggered when an item is modified in a sharepoint list or a library experience here i have a sharepoint list called service desk and as modifications are made to any of the items in the sharepoint list i would like to send a notification email to create the flow.
I will head over to create click on automated cloudflow for when an item is modified and pick the when an item or a file is modified trigger i will give my flow a name and i will click on create for the trigger action i will connect it to my sharepoint site i will pick the list service desk i will add a new step.
And pick the send and email action from the office 365 outlook connector this email i will send to the admin which is the subject will be ticket updated and here i can plug in the title of the ticket which i can pick from dynamic content the trigger action will expose all the properties or the columns coming in from the sharepoint list here i will put in the title information.
And for the ticket i would like to put in the id of the item as well in the body of the email i would like to provide additional information about the ticket and also give a link directly to that specific item in sharepoint for that i will first switch over to code view here i would like to give the title i'll pick it from dynamic content this is plain html so i'm introducing a.
Line break i will provide the description the priority is a choice column so i will pick the dynamic content that states priority value i will pick the status of the ticket once again it's a choice column in order to add a link to take the user to the specific item that has been modified i will add a couple of line breaks and here i will use the anchor tag href where i would place the link.
I will enter some commands and i will click save so i have made some modifications to this item the flow has triggered and succeeded so it should have sent the email out to the admin which is reza and here is the email the ticket number the title of that ticket and here are all the details associated with that item plus a link here to directly open the ticket if i select this.
It will redirect to that specific sharepoint item that was updated next let's take our flow one step further currently the flow is being triggered when an item is modified however there could be various scenarios in which you want to trigger your flow only based on specific conditions for example send the notification to the admin only if the priority of the item that has been updated.
Is critical in the trigger action under settings there is an option here called trigger conditions wherein you can specify one or more expressions which must be true for the trigger to fire in here if i click on add i have to directly enter the expression now i'll show you an easy way to grab the expression right after the trigger action.
I will add an action and i will pick condition my condition here is priority value is equal to critical now in a condition action if i go to the three ellipses the p code functionality is disabled so i cannot grab the code behind this specific action which would be the expression that i would like to plug in into my trigger condition as an alternative you can copy this.
Condition action to the clipboard i am leveraging notepad i will go ahead and paste the code in here control v right here at the bottom you will note that i have this expression syntax this is what i would like to focus on the expression action here is called equals to get the priority columns value the expression is as follows and then i'm.
Posts Related:
Comparing it with critical now this is something that i can take help of and go back to the settings for
My trigger action here when you're putting your trigger conditions the first thing to do is put the add symbol and then plug your condition so i will leverage equals in brackets i will put the first parameter that will be this specific expression so i'll paste that in here comma my text in single quotes which i'm trying to compare against which is.Critical and i will close my equals function once i'm done with this i can click done now this condition that i added i no longer needed i will delete this and just to confirm that the expression that i've plugged in is correct i will add an action here called compose and for the trigger condition that i plugged in i will copy this and paste it directly in here if the expression is accurate it will.
Show this expression symbol right here if for some reason i made a mistake here let's say i missed the last part of the bracket if i copy this and if i try and paste it in here it won't paste that expression so if the expression is accurate it should plug in that expression syntax for us another option to get the expression of course is by directly going to the expression editor and right here i can use the equals function because i'm trying to compare two values.
The first parameter of equals i can pick from dynamic content that is priority value it will put that same expression here comma in single quotes i'm trying to compare it with critical i can click on ok it will only save the expression if it is valid so that same expression is right here which i can simply copy from this expression dialog box go back to the trigger condition.
And paste it right here and i have to ensure that at the beginning i have the add symbol i'll click on done and my trigger condition is set i've removed the compose action here since i no longer need it and i will go ahead and save my flow this time the flow is listening to an item being modified and the priority must be critical i will update a couple of items this one is the event banner item.
Let's say i change the status to closed and i click saved so i've made an update to this item but the flow will not trigger because the priority for this item is low let's pick laptop ram i edit this item here i change the priority to critical i reopen the status of this item add some commands click save this item has now been modified and the priority is critical.
That means the flow would trigger for only this item which is laptop ram and the only email that i have received is for that specific ticket which is ticket number 24 laptop ram the beauty of trigger conditions is you can add multiple trigger conditions in here for example priority is critical and the status should be closed only then i should receive a notification for it i can simply add another trigger condition.
Right here for the status column the importance of trigger conditions is your flows only run when you truly need them to run you do not want to waste your flow runs next let's take this one level further when the item is modified we are notifying the admin about the item that has been modified however in the notification email i would also like to specify which columns have been updated also what were the previous values for those columns.
We need to ensure that for our list or library experience under versioning settings we have the create a version option turned on so this needs to be set to yes and you can also define how many versions of an item you would want to keep once you have versioning enabled as changes are being made to specific items it will keep creating a version for that item so let's take an example of laptop ram.
Here if i go to version history i can see the last three versions of the item
The changes that were made who made the changes and the date and time at which those changes were made now if we need to grab this information in flow we have an action called get changes for an item or a file properties only i will pick this action site address i will pick my sharepoint site i will.Pick my sharepoint list i need the id of the item for which i want to fetch the changes for here i will pick id dynamic content from the trigger action since you can define an item version label number or you can also specify a date from which you want to track the changes to the latest version the trigger action will already have the details of the latest version of the.
Item but i need to go one step back to the previous version so what i will do here is i will leverage an expression subtract which is sub what is the version number that i will get from dynamic content the property is called version number so i'll pick that from the trigger action this will return a string subtract works on integers and decimal numbers.
So this i will type cost to decimal i'll put a comma the second parameter is the number to remove from the first parameters i would like to subtract one that means it will go back one version so i will click ok now for testing purposes i will click on test and run this flow automatically with the recently used trigger and pick the last.
Run of my flow and run this flow again if you look at the output of get changes for an item or a file action and if i head over to show raw outputs the json output property body has a property called column has changed and here it lists out all the columns within that sharepoint list that have changed for my laptop ram item if we look at the version history the three changes that were made were in the priority column.
Status column and the commands column and those are the three columns priority status and commands that have the flag associated with it as true however it does not give me the previous value neither does it give me the current value all it states is whether the column has changed or not this is not in an array format it's basically an object that has my column names so if i would like to know has description changed has department changed i would literally have to write.
Logic to directly point to those specific attributes in this json object i will show you a technique through which we can take this data point which is column has changed and convert this into an array which will have two properties the name of the column and whether that column has changed or not the advantage that it will give us is we can quickly filter that array to know which columns have truly changed.
And once i know which columns have changed i can fire additional queries to get their previous values and i can post that out in the email notification to my admin i will edit my flow i need an array variable to hold the previous values and the names of those columns so i will add an action i will use initialize variable i will rename this action.
To previous values array variable i will call this variable where values this will be of type array and it will be an empty array to start with i will add an action called scope scope basically allows us to group actions together it makes your flow look a lot cleaner i will rename the scope to get previous values in here i will add an action.
It is a data operation action called select for from i will plug in the following expression all of the expressions that i'm plugging in and the flow itself that i'm creating i will make it available on my github repo the link will be in the description for this video i've plugged in the expression i'll click ok i will explain what this expression does i am grabbing that specific object which was column has changed converting it to.
A string and then i'm leveraging the replace function to replace the object nodes which are those two curly braces with empty strings and then i'm splitting that entire string by comma so this will give me an array of all of those values inside that column has changed object now from that i need two key aspects column name i'll plug in the expression item will give me the current item in.
The select action the property column has changed is what i was splitting to get that array and in there i have the name of the column then i have a colon and then i have true or false which defines whether the column has changed or not so here i'm splitting it with colon and getting the first value from it which is the name of the column and in there since i have those double quotes i am using the replays function to replace it with an empty string so this will give me the exact name of that.
Column and to grab the value i will use the expression once again split item with colon but this time pick the value at index 1 which will be true or false next i would like to filter this array so i will leverage the filter array data operation the from will come from the output of select filter the items in the array where.
The item value is equal to true i only need those column values that have changed now once i have this information i need to get the previous values for these columns of this specific item we have an action and flow called send an http request to sharepoint here i will pick my site address once again the method will be get the rest api.
Endpoint to get the details of the fields of the item for a previous version is as follows underscore api web lists get by title in single quotes i need the title of my list which is service space desk slash items off in brackets i need to put the id of the item and that id i will get from my trigger action which is when an item or a file.
Is modified from this i would like to get the versions question mark dollar filter is version label equal to here i need to plug in in single quotes the version number and that version number is something that i have already done in the get changes for an item or a file action so i will simply copy this and paste it right here inside single quotes.
And here i can also define which fields i would like to get so i will put an ampersand dollar select equal to all i need to do is list out my column names comma separated and the filter action here already has the names of the columns that have changed now filter array the output of this array will have the column name and the value i only need the column names so i will add another action here called select.
I will call this select column names from will come from the body attribute of filter array and under mapping i will use the expression item off my key that i had defined here which was column name i will click ok so this will give me purely an array of all the column names.
But here i need to provide the column names comma separated so i will use the expression join the output of select column names this i will join with comma i will click ok this now completes the uri for the rest api call that i would be making to grab the previous version of this item and only select the columns that have truly changed and before running the flow.
The filter array action where we added this filter criteria go to edit in advanced mode and make sure that around the word true we have single quotes now let's test this flow with the previous flow run if we focus on the scope action select the output is an array of all those key value pairs that we defined column name has the name of the column and value is.
True or false which tells us whether that column has changed or not and value here comes out in the form of a string and that's why i added those single quotes in true because we are comparing it to the text true in order for us to filter this in the next step so if we look at the output of filter array this will only have those columns that have truly changed and then was the action to only get the names of the columns that have changed.
And here is our rest api call output it gives an object that has body d results this is an array and in this array we only have one item because we are only getting the version for one item and in here are the previous values of those columns that have changed now these are the values that i would like to send in the notification email so the admin knows what the previous values were and which columns changed.
So now i need that array which is the array that i created initially which is var values to have the names of the columns and the previous values that i will get from the send an http action so after this i will add an action i will use the apply to each loop to loop through all the column names array and in this i will use append to array variable since i will be adding things to var.
Values and in here i would like to create an object that has two properties column and value column should have the name of my column that i can simply get with the expression item that is the current running item of my for loop which is nothing but the names of my columns and now to get the value for that i have to get the information from the send an http action in here it's an array.
But it only has one record in that array so i will have to point to the row at index 0 and from there i would like to grab the value for the specific column name which is nothing but the item property and for that as well i have an expression ready that i will plug in the expression is body send an http request to sharepoint from there go to the node d then go to results then pick the first value and from there go and pick the attribute.
That has the name of the column which i can directly get from the item function and to put this information inside the email in an html formatted manner right at the top of the scope action i will initialize another variable i will call this html code this will be of type array as well initialize to empty after this apply to each loop completes.
I will add another apply to each loop that will loop through my array variable which is where values and inside this i will use append to add a variable and i will append information to where html here i can write information like column to get the name of the column i'll use the expression item column that's coming from this key.
So column so and so has changed i can put a line break here and say previous value is item of value i'll click ok and i would like to highlight the previous value in bold i can do that as well right here and to use that in my send an email action right before the link.
I will use the expression here join from var html a line break because i would like to have all those column names listed out one by one in a new line i'll click ok now let's test this flow out the flow has triggered and completed successfully and here is the email that the admin receives it has all the current information on the top and these are all the columns that have.