1. Home
  2. Knowledge Base
  3. Microsoft
  4. Power Automate
  5. Retrieve previous versions of SharePoint list items in Flow
  1. Home
  2. Knowledge Base
  3. Microsoft
  4. SharePoint
  5. Retrieve previous versions of SharePoint list items in Flow

Retrieve previous versions of SharePoint list items in Flow

There is no action in Flow yet to access the version history of SharePoint list items (or documents). So how can we get to older versions of a list item in Flow, including all the old column values? A customer asked today if there is a way to use a flow to see if a certain column has changed (when an item changes), and then … do things.

Luckily, we have everything we need to accomplish this with the help of our best friend: send an HTTP request to SharePoint.

Here are the main steps:
Trigger for an element created by changed, add trigger condition so that it is not triggered when created (as this triggers unnecessary runs)
Calculate the previous version number so we know which version to look for
Retrieve all SharePoint list item versions from SharePoint using the HTTP request
Analyze the result (JSON) from SharePoint
Loop all versions and drag out the desired version (previous version)
Do things.

Configure the trigger with condition
First go to the trigger step settings:

Then add the following condition to ensure that the flow is only executed if the version is NOT 1.0:

not(contains(triggerBody()?[‘{VersionNumber}’],’1.0′))

Calculate the previous number
The next step is to calculate the previous number using a “Compose” action. We can do this by using the sub expression with a nested int function to convert the version number to an integer (so that ‘sub’ gets two integers to work with). And then we simply add “.0” after the expression to get the correct format (“2.0” and not just “2”).

sub(int(triggerBody()?[‘{VersionNumber}’]),1)

Call up SharePoint and retrieve the version history of the SharePoint list
To get the version of our list element, we call HTTP and pass the ID of the list element. Note that the title of the list is the display name and not the system name / URL. Even if you were a good developer and gave the list the system name “catvisitorslog” to get a nice and clean URL, the HTTP call wants “cat visitors log”.

Analyze the JSON result
This is a little trickier if you have not worked with JSON before. Before you add the action itself. Save the flow and execute it to test whether the HTTP call to retrieve versions works. Then copy the entire JSON block from the body section under the outputs:

Then go back to edit the flow and add the Analyze JSON action. Add the output text from the “Get versions” HTTP call as content and then click “Use sample payload…” to paste the JSON code you just copied. This tells the flow what the data structure looks like and how it is analyzed.

Loop all versions and … do stuff Our final step is to go through the versions we just analyzed, determine which version we want to pull, and then do something. In this example, I save the value of the “Office location” column to see where something has moved. First create an Apply for each and specify the results from the “Parse VersionHistory from JSON”, as this contains all our versions. Then add a condition that takes the VersionLabel from the looped element (under “Parse VersionHistory from JSON”) and compare it with the output of the previously created “Calculate PreviousVersionNumber” step. This checks each loop for the version The number of the loop is in fact the previous version we want to target. For example, if there are 4 versions of the element, version 1.0, 2.0 is run through and validated as false. However, when it gets to 3.0, it becomes true on validated and we can start working our magic! In this example, I only grab the value for office location and save for further logic. So if you run it, you will get the location value:

Source: https://www.catapultsystems.com/blogs/get-previous-versions-of-sharepoint-list-items-in-flow/

Dieser Beitrag ist auch verfügbar auf: Deutsch (German)

Was this article helpful?

Related Articles

Submit a Comment

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

Published on - 3. Nov 2020
Modified on - 1. Apr 2024
Views - 125
Likes - 0

Do you need help?

Kontaktiere uns gerne :-)
Contact Support
Skip to content