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 Name | Field Type |
OrderID | Number |
Order Name | Single line of text |
Order Status | Choice (New, Approved, Shipped, Completed) |
Quantity | Number |
Order Description | Multiple lines of text |
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.
Step # 2 Make REST call using HTTP to get top 2 versions of the item
# 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
# 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
# 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.