How to take an action in Power Automate only when certain field’s value have changed?

Summary

Here is the scenario, there is a list named “OrderList” with the following five fields. The end users change any of these fields except Order Status. The Order Status field is changed externally.

Field NameField Type
OrderIDNumber
Order Name Single line of text
Order StatusChoice (New, Approved, Shipped, Completed)
QuantityNumber
Order DescriptionMultiple lines of text
OrderList fields

The need here is when the Order Status change from one state to other the Power Automate Flow has some business logic. The question is how to check only the Order Status has changed from old value to new value. For example, Approved to Shipped status has multiple business actions and emails to be sent.

The solution to such need is to enable the “versions” in SharePoint List.

Step By Step Solution

Note: Please make sure you have enabled versions for your SharePoint List.

Step # 1 Create “When an item is created or modified” trigger flow

In this step select Site Address and the List Name.

Flow Trigger

Step # 2 Make REST call using HTTP to get top 2 versions of the item

Make a REST call using Send HTTP Method to get last two versions
# copy the following in Uri, make sure you change list name
_api/web/lists/GetByTitle('OrderList')/Items(@{triggerOutputs()?['body/ID']})/versions?$top=2

# copy the following values in Headers

{
  "accept": "application/json;odata=nometadata"
}

The above call will provide the results in the following format. The value JSON array has the data we need to extract the old and new values for the order status. The first value is the New value and second item in the array is an old value of the Order Status. e.g. the below data clearly shows that the Order Status was changed from New to Approved.

{
  "value": [
    {

      ... removed other data for the brevity
      "VersionId": 3584,
      "VersionLabel": "7.0",
      "ID": 1,
      "OrderName": "Laptop",
      "OrderStatus": "Approved",
      "Quantity": 11,
    },
    {

      ... removed other data for the brevity
      "VersionId": 3072,
      "VersionLabel": "6.0",
      "ID": 1,
      "OrderName": "Laptop",
      "OrderStatus": "New",
      "Quantity": 11,
    }
  ]
}

Step # 3 Extract the field values using Select operation

Us Select to extract only the OrderStatus field’s last top 2 versions we need.
# use the following formula in the From.
outputs('REST-GetTop2Versions')?['body']?['value']
# use the following formula in the Map
item()?['OrderStatus']

Step # 4 Store the OrderStaus’s New and Old value to variables

Storing Order Status New and Old values

# for New OrderStatus value us the following formula
first(body('Select'))?['OrderStatus']


# for Old OrderStatus value us the following formula
last(body('Select'))?['OrderStatus']



Step # 5 Using the New and Old variables do the comparison to take business action.

The final step is now up to your business actions. Basically you can use the above two old and new variables to do the comparison if the value have changed, or if values have changed.

Conclusion

There is no out of the box trigger to Tigger on the field. This is a simple ways to find out field values changing.

About Pankaj

I am a Developer and my linked profile is https://www.linkedin.com/in/pankajsurti/
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s