Publishing page rollup approval using Microsoft Flow

One of our clients had a requirement to approve pages created by users within their Intranet in order to have them displayed on the home page. In this particular case we’re using a classic SharePoint publishing site with a custom search based rollup Web Part from Intelligent Decisioning’s Mercury Intranet product. We didn’t want to go down the painful road of full SharePoint Content Approval as they wanted the pages visible in search as approval was only needed for home page rollup element.

I thought I would post the solution I came up with just in case it’s useful for the community so here you go! This same approach will work fine with with another type of site e.g. a Team Site AND now that metadata can be applied to modern pages, this could be implemented on a Communications or Hub site. You could also use this for documents if you wanted! For the rollup side of things you could use a Content by Search Web Part for example with a custom template.

To control showing the pages on the homepage, there are two columns added to the page Content Type/Layout – ‘Show on Homepage’ and ‘Show on Homepage Approved’. The former allows the user to specify whether they want to show it on the home page, the latter is a hidden column which the approval flow controls. Both of these are simple yes/no columns. The search query used on the home page rollup displays content where both of these column values are true.

I’ll go through each section of the flow step by step (mainly because I can’t screenshot the whole thing as it’s too big!) and explain how it works.

Step 1 – Getting the Page Body

Start of our flow

The first part of the flow is pretty simple and essentially runs whenever a file (page) is modified in the Pages library of a specific site. We initialise some variables for easy reference later. The most important part is the ‘Get Page Item’ action which is a SharePoint HTTP request action. We need this to identify whether the page has been published (as we want our flow to run only when the page is published by the user) – more on this later. We then have a condition which in this case checks if the page matches a specific Content Type as we are only using this approval for news articles.

Step 2 – Checking the Page Version number

Checking for a published version

If our content type matches, I then do another check to see if the ‘Show on Homepage’ column I mentioned earlier is set to true. 

We then need to use a Parse JSON action to parse the body of the page which we retrieved from the HTTP action earlier. To generate the schema, run your flow and copy the content of the body outputted from the earlier action. Paste this into the sample playload dialog and hey presto you will have your schema. The body contains the all important ‘
OData__UIVersionString’ property which stores the version number. As we only want to do approval for published pages, we need to check for where the version number ends in .0 i.e. it is not a minor version. Use the following expression to achieve this – 

indexOf(body(‘Parse_JSON’)?[‘d’]?[‘OData__UIVersionString’], ‘.0’)

Step 3 – Starting the approval

Starting the approval

Now we are ready to start the approval. You will see that I set the value of the FolderPath variable that I created earlier. This is so I can build up a link to the file inside the approval task (for reference this is needed because the pages for this client reside in subsites). If you are doing this for a top level pages library only then you won’t need this part. The rest of this section is self explanatory and just assigns a Flow approval task to a set of users.

Step 4 – Checking out, updating and checking in

Checking out the page

Once we have checked the approval task response, we can set the value of our hidden ‘Show on Homepage Approved’ column. However to do this we need to overcome a stumbling block – checking the page out and back in again! Because the page will be published and therefore the properties cannot be updated – if you try and update the properties directly Flow will complain – trust me! This process is very similar to how you used to work around this in SPD workflow but Flow makes it easier for us thankfully!

To check out the file, we use another SharePoint REST call, this time a POST to the CheckOut() endpoint. Once this is done, we use a SharePoint – Update Item action to set the value of the hidden column to true. 

Checking the page in and finishing up

The last part of the Flow as you probably guessed is to check the page back in, again a REST call achieves this but this time to the CheckIn endpoint where you will need to add a comment and a check in type, the type establishes whether it is Minor or Major – 1 equals major. Once that is complete – we are done!

Now all that remains is to create a page/document, check the Show on Homepage option and test the Flow. All being well you should see the page/document in your rollup Web Part once a search crawl has ran.

Hope this helps someone out! If anyone wants an anonymised copy of the Flow then feel free to ask.

Leave a Reply

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