July 14, 2021

SharePoint – Broken Links Solution

A recent chat with a customer who was looking for a solution to check modern SharePoint pages for broken links got me thinking ?

I wondered whether this could be achieved using the Power Platform (specifically Power Automate). Fast forward a few days and I had a working solution ? 

This post is all about the solution I created and how you can use it too!

Solution Components

  • Flow – ‘Check Broken Links’ (Checks for broken links and creates items in the list below). 
  • SharePoint List – ‘Broken Links’ (Used to store a list of pages that have broken links along with the links that are flagged as broken).
  • Flow – ‘Broken Link validation’ (Sends adaptive cards to page authors allowing them to edit/update the page and flag the links as validated). 

Note – The solution can handle SharePoint links and external web links.

How it works (High level)

  1. Flow (‘Check Broken Links’ runs when pages are created or modified in the Site Pages library.
  2. Verifies that the page is published by checking the version number. We only check for broken links when the author has published the page. This way we can capture all possible links in case they are editing it multiple times in draft and adding additional links. 
  3. Retrieves the page content using the SharePoint REST API (Send HTTP request to SharePoint action).
  4. Converts the page content (returned as HTML) to plain text.
  5. Extracts possible links by splitting the text. 
  6. Checks if the link is a SharePoint link or a web link.
  7. Sends a HTTP request to the link (using the SharePoint action if it is a SharePoint link or standard HTTP action for a web link).
  8.  Appends the link to an array IF the HTTP call fails.
  9. Creates/or updates an item in the Broken Links’ list.
  10. Flow (‘Broken link validation’) runs when items are created/modified in the Broken Links list.
  11. Gets the page details (Id of the page is stored in the Broken Links list).
  12. Sends an adaptive card that requires a response to the page author.
  13. The user checks the list that are flagged in the adaptive card and uses the button provided to edit/update the page. 
  14. Once the page has been updated, the user clicks the ‘Done’ button, the flow resumes.
  15. The status column in the Broken Links list is updated to ‘Validation Complete’
  16. Future edits to the page will restart the above process.

The solution in action

This is what the solution looks like in action:

  1. Creating a page with some broken links.
SharePoint page with broken links.
Modern page with broken links.
  1. Item gets created in the Broken Links list. 
Screenshot of broken links list.
List item created for the page in the Broken Links list.
  1. Adaptive card is sent to the page author.
Screenshot of broken links adaptive card.
Broken links adaptive card.
  1. User clicks ‘Done’ after updating the page and correcting any potential broken links.
  2. Adaptive card displays an update message and the status of the item in the Broken Links list is updating to ‘Validation Complete’.
Screenshot of broken link adaptive card update message.
Adaptive card update message.
Screenshot of the updated broken link list item.
Status of broken link list item updated.

Deploying the solution

So how do I deploy it?? I hear you ask. Simply follow the steps below to deploy. 

The deployment steps assume a good level of knowledge with the PnP PowerShell module and Power Automate.

  1. Download all the neccessary files from here – https://aka.ms/spobrokenlinks
  2. Apply the provided PnP template (‘brokenlinkslist.xml’) to the site you wish to deploy the solution to. This will create the Broken Links list. The template was extracted from a Communication Site so it may display a warning message if you are applying this on non comms site (you can ignore this warning as we are only creating a list).
  3. Import both of the flows into your environment using the zip files provided – ‘CheckBrokenLinksFlow.zip’ and ‘BrokenLinkValidationFlow.zip’.
  4. Update the data connections with valid connections in your environment.
  5. Edit the ‘Check Broken Links’ flow.
  6. Update the Site Address in the trigger to the site in which you want to check for broken links. The Broken Links list must reside in this site.
  7. Update the values for the following variables:

SharePointTenantName: Name of your SharePoint tenant (excluding onmicrosoft.com e.g. contoso

SharePointTenantURL: URL to the root site in your SharePoint tenant e.g. https://contoso.sharepoint.com

SiteURL: Same URL used in the trigger (the site you want to check for broken links) e.g. https://contoso.sharepoint.com/sites/thelanding

  1. Save the flow.
  2. Edit the ‘Broken link validation’ flow.
  3. Update the Site Address in the trigger to the same URL used in the ‘Check Broken Links’ flow.
  4. Update the values for the following variables:

SiteURL: Same URL used in the trigger (the site where the Broken Links list resides).

The solution should now be deployed and ready for use. To test it, simple create a page with some broken links and wait for the flows to run and the adaptive card to come through ?

Notes

Currently the solution does not take into account links that have redirects configured where 302/303 status codes are returned. These may be flagged as broken links and the page author will need to determine if they work before validating the page.

The solution requires a premium license for Power Automate as it leverages the HTTP connector. As this is not initiated directly by a user, there is no need to license all users. Either a single license for the creator of the flow would be enough or you could use the ‘Per flow’ license type. 

As always, I would really appreciate your feedback on this solution and how it could be improved.

You may also like...

Leave a Reply

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

WP to LinkedIn Auto Publish Powered By : XYZScripts.com