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.

Inspiration

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.

Be aware that there are definitely other approaches out there. April Dunnam also has a nice article & video on how to get the SharePoint column changes.

The 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.

The workaround

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.

NameTypeValue
HasColumnChangedFixedString
ObjectNoteObject
HasColumnChangedArrayArray[]
CountInteger0

fourvariables

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.

versionlist

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.

applytoeach_expression

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 😉

incrementvariable

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.

appendtostringvariable_hascolumnchangedfixed

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.

condition_checkcount

8. Add a Set Variable action in the if Yes section. Use the following expression below to set the ObjectNote variable.

setobjectnotevariable

9. Add an Append to array variable action. Use the ObjectNote variable in the value field to append it to the HasColumnChangedArray variable.

appendtoarrayvariable_objectnote

10. Add a Set Variable action. Use the value 0 to reset the Count integer variable.

countreset

11. Add a Set Variable action. Use the value null to reset the HasColumnChangedFixed variable.

hascolumnchangedfixed_reset

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.

itemvalue_true

The end result

When you run the flow you should get a result like below. As you can see the Change column has changed. filterarray_endresult

Happy testing!

You may also like...

5 Responses

  1. Neil Hatch says:

    Have you ever considered getting the actual changed data for the version too? In addition to using the Get Changes I’ve called a Send an HTTP request to pull back versions details.

    I’d like to get to a point where only the changed field and value is returned for each version, I’ll then pass it back to my P.App.

    Any thoughts on how to extract to value too?

  2. Neil Hatch says:

    Great blog….should have said that first!!

  3. Izabela says:

    This is amazing! Thank you so much for posting this, worked like a charm!

  4. Dennis says:

    Hi Izabela,

    Great to hear it worked, thanks for the nice feedback 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.