Press "Enter" to skip to content

Compare Microsoft Word Documents with Power Automate

Our team have been working hard over the past few months to build and release our latest action for the Encodian connector, ‘Compare Word Documents

The action will be available within all Power Automate regions by mid May 2021.

The ‘Compare Word Documents‘ action provides document comparison capabilities by generating a comparison word document containing the differences between the two source documents provided (Tracked changes in Microsoft Word).

This post shows how to compare two versions of a Microsoft word document held with a SharePoint library.

Compare SharePoint Document Versions Automatically

NOTE: The following steps can be performed on DOC, DOCX, DOT, DOTX, DOCM, DOTM, RTF and PDF Files. However please note that PDF comparison is limited to Microsoft Words native support for comparing such files.

1. Create a new ‘Automated cloud flow‘ flow in Power Automate

1.a. Flow name: Provide a name for your flow

1.b. Trigger: Select the ‘When a file is created or modified (properties only) SharePoint trigger action

1.c. Click ‘Create

2. Configure the ‘When a file is created or modified (properties only)‘ SharePoint trigger action as required:

3. Add a condition action and configure to check whether the current document is a word document by evaluating the ‘Filename with Extension‘ property.

3.a. Input value: Select the ‘Filename with Extension‘ property provided by the ‘When a file is created or modified (properties only)‘ SharePoint trigger action

3.b. Operator: Select the ‘ends with‘ operator

3.c Value: Enter ‘docx

4. Within the ‘If No‘ branch add a ‘Terminate‘ action

4.a. Status: Set to ‘Succeeded

Next, we will add logic to the flow to check the previous version of a Microsoft word document with the current version of the same document. For this example, the SharePoint library has been left with the default version configuration (major versions only).

5. Within the ‘If Yes‘ branch add another ‘Condition‘ action

5.a. Input value: Select the ‘Version number‘ property provided by the ‘When a file is created or modified (properties only)‘ SharePoint trigger action

5.b. Operator: Select the ‘is not equal to‘ operator

5.c Value: Enter ‘“1.0”

6. Within the ‘If No‘ branch add a ‘Terminate‘ action

6.a. Status: Set to ‘Succeeded

NOTE: You may have noticed that the value passed to the previous condition has changed to 1.0 as opposed to “1.0”. This is just the Power Automate UI changing how the value is rendered, but you must not enter 1.0 as opposed to “1.0”, if you do this Power Automate will convert the value of 1.0 to 1 and therefore the condition will not evaluate correctly.

7. Within the ‘If Yes‘ branch add a SharePoint ‘Get File Content‘ action

7a. Site Address: Set as per the trigger actions value

7.b: File Identifier: Select the ‘Identifier‘ property provided by the ‘When a file is created or modified (properties only)‘ SharePoint trigger action

Unfortunately, there isn’t a native Power Automate action to retrieve the previous version of a document from SharePoint, therefore we’ll use the SharePoint ‘Send an HTTP request to SharePoint‘ action to do this.

8. Add a SharePoint ‘Send an HTTP request to SharePoint‘ action

8.a Site Address: Set as per the trigger actions value

8.b. Method: Select ‘GET

8.c Uri: Follow these instructions:

The URI is well… complicated, and very sensitive! the schema of the URI is as follows:

/_api/web/getfilebyserverrelativeurl('<ServerRealtiveFilePath>')/versions('<versionNumber>')/$value 

Example below:

/_api/web/getfilebyserverrelativeurl('/sites/demo/demo.docx')/versions('512')/$value

Simple! but a little fiddly to configure Power Automate to generate the correct values. The <versionNumber> value is not actually the 512th version, it is actually version 1.0… and version 2.0 is 1024, version 3 .0 is 1536 so on so forth. To obtain the correct value we need to obtain the current version number value, subtract 1 (to get the previous major version) and then multiply the result by 512 using a Power Automate expression, see below:

mul(sub(int(substring(triggerOutputs()?['body/{VersionNumber}'],0,indexOf(triggerOutputs()?['body/{VersionNumber}'],'.'))),1),512)

Ensuring you’re flow actions are exactly as per this flow copy and paste the following into the URI field:

/_api/web/getfilebyserverrelativeurl('/sites/demo/@{triggerOutputs()?['body/{FullPath}']}')/versions('@{mul(sub(int(substring(triggerOutputs()?['body/{VersionNumber}'],0,indexOf(triggerOutputs()?['body/{VersionNumber}'],'.'))),1),512)}')/$value 

You will need to update the ‘/sites/demo‘ value to the URL of the site collection / web you are working with.

9. Add the Encodian ‘Compare Word Documents‘ action

9.a. File Content – One: Select the ‘File Content‘ property provided by the ‘Get File Content’ SharePoint trigger action

9.b. File Content – Two: Select the ‘body‘ property provided by the SharePoint ‘Send an HTTP request to SharePoint‘ action

The Encodian action will return a Microsoft Word document detailing the differences between the two documents provided.

For this example I’ll simply email the resulting document for review.

10. Add the ‘Send an email (V2)‘ Office 365 Outlook action

10.a. Configure the ‘To’, ‘Subject‘, ‘Body‘ and other fields as required

10.b. Attachments Name – 1: Select the ‘Filename’ property provided by the Encodian ‘Compare Word Documents‘ action

10.c. Attachments Content – 1: Select the ‘File Content‘ property provided by the Encodian ‘Compare Word Documents‘ action

Your final flow should look very similar to:

Now execute your flow by uploading or creating a new document version:

And the document:

Final thoughts…

Hopefully, this post provides a good example of how you can utilise the Encodian ‘Compare Word Documents‘ action within Power Automate to compare Microsoft Word documents.

We hope you’ve found this guide useful, as ever please share any feedback or comments, all welcome!

Be First to Comment

Leave a Reply

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