Using Microsoft Flow to know when a Modern Page is published

Reading Time: 3 minutes

For a business solution I was recently building using Microsoft Flow, I needed to know when a modern page had been published to automate additional processes after it. It turns out, this was not as straight-forward as I thought it would be. I decided to write this post to help others who find themselves needing to do the same thing.

How can you tell when a page is published? A published page can be identified by its version number. If it’s a major version (1.0, 2.0, 3.0, etc.), it’s published. If it’s not(1.2, 2.1, 4.1, etc.), it’s a minor version and therefore hasn’t been published.

Note: this is also true with the new Page approval workflow since that still operates under the major/minor version numbers at the page level.

Knowing this, we can check the version number in a Flow to determine whether or not a page has been published. Unfortunately, the version number (or the approval status) is not exposed in Microsoft Flow for a Site Pages library.

Here are the steps I took to get the version #:

  1. Build a flow triggered when a site page is modified.
  2. Retrieve the site page by its ID using the ‘Send an HTTP request to SharePoint’.
  3. Parse the version # from the JSON returned
  4. Check if the version # ends in ‘.0’ and if it does, it’s published!

Read on for details on each step.


Step 1: Trigger-based flow

Select the ‘When a file is created or modified (properties only)’ as the Flow trigger. Once you provide the sitename where your Site Pages library exists, you’ll notice the Site Pages library doesn’t show in the drop-down. That’s ok! Just provide the guid of the library instead.

To get the guid, browse to the Site Pages libary on the SharePoint site, go to Library settings and select the value after the List= parameter on the URL. Decode it.

Paste the guid into the Library Name and select the Site Pages folder (image):

SitePage guid


Step 2: Retrieve the site page

There is no version number property returned from the previous step to indicate if the page is published or not. To retrieve the version #, we need to get the Site page again using the REST API via the Send an HTTP request to SharePoint action with the ID from the previous step:

Send HTTP request to SharePoint


Step 3: Parse the Version # from the returned JSON

The JSON returned from the previous step contains the version number in the element OData__UIVersionString. In the Flow, create a string variable (VersionNumber in this example) to hold the version number and provide this expression for the value:

body(‘Send_an_HTTP_request_to_SharePoint’)[‘OData__UIVersionString’]
[Update March 2022] Thanks to a blog reader, Eric, the original code in this step will now fail with “invalid template”. Resolved with this: body(‘Send_an_HTTP_request_to_SharePoint’)[‘d’][‘OData__UIVersionString’]

Initialize Variable


Step 4: Check if its a major version

It’s now a simple check to look at the version number to determine if its major (i.e. published).

Condition

If the above is true, its published. If it’s false, it’s draft! 🙂


What’s the use case?

If you have additional business processes you want to automate with your Flow after a type of page is published, this allows you to do that. I’m using this technique with multiple Site Page content types where I automate different actions depending on the type of Site Page published.

Thanks for reading.

-JCK

20 comments

  1. Now I understand why you asked 😉

    Less than a week between the question on twitter and the blog post on the solution.

    Thanks for sharing because, as Vesa wouldsay, «sharing is caring»

  2. I am having difficult initiating the above example to my SP Library. When I test the flow I get a bad request error in the second step.

    Essentially, what I’m trying to accomplish is updating a field property when a document version is major.

    1. Hi Theodore, this definitely works however the syntax on the “send an http request ” step is very particular. If you’re getting a bad request then likely something isn’t formatted correctly in your step.

      It’s difficult for me to do troubleshooting for you on that one.

      -JCK

  3. Hi Joanne. Thanks for your reply.

    I think whats causing the error is the URI and Headers fields.

    For the URI I have _api/web/lists/GetByTitle(“Site Pages”)/items(@{triggerBody()?[‘ID’]}) If its a SP Library would it be “Site Pages”?

    For the Header fields, I have exactly what you inputted in your screenshots.

    Any help would be greatly appreciated.

    Thanks, Theodore

  4. I am surprised to hear there is no flow action supports this behavior when an item is published. I believe, its a good idea to keep a point in your blog mentioning about the bill involved in the flow runs. Because our client environment has many site pages (news) who is modifying these pages regularly and each auto save (unfortunately) triggering a flow. Which is making huge number of flow runs and they are out of available runs at specific time. Unfortunately yes but this may be a worth note to add in your blog.

  5. Hi Joanne,

    Thank you for the excellent tutorial.

    I am trying to implement this when our users are posting a new News article (I wish to copy this to an additional folder we can use as an archive).

    However, I found that the flow only triggers only the initial creating of a page.

    Using your condition I can tell it has not yet been published and so the flow intercepts this. However, as soon as it is published, the flow does not seem to trigger again – even though I expected it to as technically it’s being “Modified” at that moment and should fire the flow again.

    Do you know if there is a way around this, or am I missing something here?

    Hoping you can help, thank you so much in advance.

    Kind regards,
    Rick

    1. Hi Rick, what is triggering your Flow? If it’s triggered on whenever anything is added or updated on your pages library, it should always run.
      -JCK

  6. Hi Joanne, thanks for this. It looks as though it’s going to do exactly what I need but I get a 404 error stating “List ‘SitePages’ does not exist at site…”

    There is a SitePages list, of course, any idea what could be going on here?

    Thanks
    Jason

      1. I quickly read it, I don’t have time to think about it much, I’m sure it’s fine! 😊
        -JCK

  7. the “When a file is created or modified (properties only)” trigger returns a version number for me. Is this development new since you wrote this page? can we skip the parsing json step now and just examine the returned version number value?

    1. Hi Cliff… relatively old post and I haven’t tested recently. If you can see the returned version number then definitely just use that. At the time I write the post you couldn’t. Please update your results from testing on this thread!! 😊

  8. As of 2/28/2022, the original code in step #3 failed with “invalid template”. Resolved with this:

    body(‘Send_an_HTTP_request_to_SharePoint’)[‘d’][‘OData__UIVersionString’]

  9. Or make a Trigge condition @endsWith(triggerOutputs()?[‘body/{VersionNumber}’],’.0′) if you only want flow to run on major verstions

Leave a Reply to Joanne KleinCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.