To create a flow that will do some logic implementation only when a Page is published in the Site Pages library, we need to know if it is a major or minor version. However, there is no straightforward single action to check if the document is in a major version (hence Published) or if it is a minor version which means it is still in a Draft state.
To work around the situation, we can check the Version number and see if it is of the format 1.0,2.0, and so on. A .0 notation ensures that it is a published major version or else if the version number is 1.2,2.1 and so on, we can identify that it is a minor version and hence not published
Before we start with the flow creation, let us ensure that the major/minor versioning is enabled in the library settings
Now let’s head over to Power Automate and create a flow with the trigger action “When a file is created or modified”. We will have to manually add the Site Pages in the Library name section as it does not get auto-populated
Now we need to get the version number of the file which is available as a dynamic property. Hence we will have to issue an HTTP Request and retrieve the version number as shown below:
Now let’s initialize a variable that will hold the version number retrieved from the body of the above request. Add the below expression to the value field which will get the Version Number from the body.
We will now check the variable which contains the version number and will use a Condition to see if the version number has .0 which indicates that it is a major version or else it will be a minor version. We will update the result – Major/Minor version to a custom field that we have added to the library.
Let’s add the condition that checks if the version number ends with .0 and will update the Column with Major/Minor version accordingly
Now let’s test the flow by creating a site page. On saving it, it will be saved as a minor version. This should ideally kick start the flow and will save the value minor version to the custom column.
After a while, we can see that the flow has run and has updated the column with the value Minor version
Now let’s head over to the page and Publish it which will convert it to a major version.
Heading over to the flow page, we can see that the flow has run successfully
If we go to the site pages, there as well we can see that the custom column has been set with the major version value.
Thus, we saw how to check the version number of a document and decide if it is a major/minor version and hence if it is published or not