DEV Community

thebernardlim
thebernardlim

Posted on

Power Automate - How to get previous value of updated SharePoint List Item

Currently at time of writing, it is easy to kick-off a Power Automate flow when a SharePoint list item value changes and retrieve the new value.

However, to retrieve the previous value will require some work.

Below is the solution.

Overall Flow

Full Flow



Flow Breakdown

Flow Type: Automated cloud flow

Step 1 - Trigger when an item or a file is modified

Trigger Type: When an item or a file is modified

Trigger


Step 2 - Get changes for an item or a file (properties only)

Purpose: To retrieve previous version number
Action Type: Get changes for an item or a file (properties only)

Get changes for an item or a file

The Since value will be the Trigger Window Start Token

Trigger Window Start Token


Step 3 - Send an HTTP request to SharePoint

Purpose: To retrieve all the versions of this particular updated list item
Action Type: Send an HTTP request to SharePoint

Send HTTP request

  • Uri: _api/web/lists/getByTitle('{Your_list_name}')/items(@{triggerOutputs()?{List Item ID from Step 1})/versions
  • Headers:
    • Key: Accept
    • Value: application/json; odata=nometadata

** It is important to add the Accept header to return JSON, else it will return as XML by default


Step 4 - Do a Test Run

Purpose: To get sample JSON which will be used for your next action.

After running, copy the JSON from the Outputs body section

Output


Step 5 - Parse JSON response

Purpose: Turn the JSON response into objects which we can then use
Action Type: Parse JSON

  • Content: Body of the Send an HTTP request to SharePoint action
  • Schema:
    • Click on Generate from sample
    • Paste the JSON copied from Step 4 and click on Done button Sample JSON
    • Once outside, click on 'Generate from sample' button to fill up the Schema field

Step 6 - Retrieve version of item

Purpose: Retrieve only the specific item version from the array
Action: Filter array

Retrieve item

  • From: value from Parse JSON action
  • Where:
    • VersionLabel from Parse JSON action
    • Condition: is equal to
    • Value: outputs('Get_changes_for_an_item_or_a_file_(properties_only)')?['body/SinceVersionLabel']. This value is from Step 2 - Get changes for an item or a file (properties only). There is no need to manually type this. Click on the Expression icon and choose the following in the popup window.

Expression Window


Step 7 - Retrieve value from the item version

Purpose: Retrieve value from old version and setting value to variable
Actions: Initialize Variable & Set variable (within Apply to Each control)

Here when setting the variable, you can select the column you want, in this case it was my Project field.

I then set the ProjectOldValue variable with the Project value.

Setting project value



Note that this flow can be modified as required for various scenarios, one being, if we need to retrieve the original value for an item (1st version), we can just hardcode the version value 1.0 for VersionLabel for Step 6.

Top comments (4)

Collapse
 
gyounan84 profile image
george y

had to do some tweaks but it worked! thank you!

Collapse
 
northon_da4d74b4ecb profile image
Karen Northon

Can you share what tweaks you made?