Search code examples
azuresharepointazure-logic-apps

Design a Logic Apps flow in Azure that tracks SharePoint file versions. On detecting a major version change, save the file to Azure Blob Storage


I am trying to create a logic apps flow in Azure where if the file in a specific folder of sharepoint site is updated, i need to check the versioning of that file. Sepearate the major and minor version. If there is just a change in the minor version of the file, we don't need to do anything but if the major version of the file is changed/updated we need to store the file in the azure blob storage.

enter image description here

I have created a logic app flow:

  1. Trigger to detect if any file is created or modified.
  2. Getting the content of the file
  3. In compose function, I have put in function to extract the major versioning of the sharepoint file as: split(triggerBody()?['{VersionNumber}'],'.')[0]
  4. In the condition section, the 1st param is the output of the compose function.

The problem here is i need to get the previous version of the file so that I can compare the old and new version of the file from sharepoint and if a newer version is detected, store the newer version in azure blob storage.


Solution

  • If you want to ignore minor versions and continue with the workflow only for major versions, then just inspect the version number. If the version number ends in .0 then the last change created a major version.

    By definition, any version that does not end in .0 is a minor version.

    So, use the Split function, but get the element after the decimal point and check if it's a zero. Split returns text, so you may want to wrap it into an Int() function to get a number.

    int(split(triggerBody()?['{VersionNumber}'],'.')[1])

    enter image description here

    Here is a file that I just changed and that is version 1.1

    enter image description here

    And here is the file published as a major version 2.0

    enter image description here

    Edit: Another way to achieve the same outcome is to use a trigger condition in the trigger. The condition in the screenshot below uses the formula

    @contains(triggerBody()?['{VersionNumber}'],'.0')

    enter image description here

    The following screenshot shows two documents recently edited. The "Collaboration" file is still in a minor version, the "Controlled" document was published as a major version and triggered the workflow.

    documents in library

    Workflow run history