How to retrieve changed ColumnHasChanged fields
This one has been on my to-do list for a while. Dynamically retrieving the columns which have changed in a SharePoint Online list item or file. This article explains how you can use an expression with the ColumnHasChanged collection.
I was triggered again (pun intended) by the comment from Matthew Harding below.
I looked at transforming that data (ColumnHasChanged collection) using every trick in the book but I could not see a method of re-configuring the data into a suitable format.
Power Users Community thread: Get Column Changes – Filter an Array.
I have tried to solve this puzzle a couple of times. But this time I was eager to find an expression for this challenge.
The SharePoint Get Change for an item or file (properties only) action is very useful. It has fields for the individual fields which have changed. However, there is also a field called Has Column Changed. Below is an example of a value of that field. As you can see it has the following structure: fieldname: value.
In an ideal world we would also have the field and value labels, that would make filtering with a Filter Array a bit easier.
In this example we will be using one specific list item. One column has been changed since version 1.0, but we don’t know which field. Lets find that out with the following setup!
1. Add the Manually trigger a flow action.
2. Add four initialize variable actions. Below is a table with the name, type and value for each of the variables.
3. Add a Get changes for an item or a file (properties only) action.
In this example I am using a list called VersionList and comparing version 2.0 with 1.0.
4. Add a Apply to each action. Use the following expression for the Select an output from previous steps field.
This expression uses a couple of replace functions to tidy up the ColumnHasChanged value. It also uses a join and some split functions to make it usable for the append to string variable action later in the flow. The boolean value has space character in front of it. This way we can easily spot the difference between a field name and a field value.
5. Add an Increment Variable action within the Apply to each action. Increment the Count integer with a value of 1.
I want to create field value pairs. So, I am counting till 2 😉
6. Add an Append to string variable action within the Apply to each action. Use the following expression to append to the HasColumnChangedFixed variable.
In this expression I add the Field and Value labels to the temporary string variable.
7. Add a Condition action within the Apply to each action. Check to see if the Count integer variable is equal to two.
If the count equals two we will have a field and a value. This means we can write the temporary string variable value to our permanent array variable with a couple of actions.
8. Add a Set Variable action in the if Yes section. Use the following expression below to set the ObjectNote variable.
9. Add an Append to array variable action. Use the ObjectNote variable in the value field to append it to the HasColumnChangedArray variable.
10. Add a Set Variable action. Use the value 0 to reset the Count integer variable.
11. Add a Set Variable action. Use the value null to reset the HasColumnChangedFixed variable.
12. Collapse the condition action. Add a Filter Array action below it. Use the HasColumnChangedArray variable in the From. Use the comparison from below.
With this Filter Array we can check which fields have changed for the list item.
The end result