What if you have a need to run a flow every time when a document is published in SharePoint? Out of the box SharePoint connector doesn't have "published" trigger, the only triggers are a document created or modified.
"Send an HTTP request to SharePoint" to the rescue
While you technically can't use "Document published" trigger, you can use document updated trigger and check the status of a document using REST API. You can use _api/web/GetFileByServerRelativeUrl API to check the file state. There are some properties available for a file. The most interesting for us is below:
CheckOutType vs SPFileLevel
SPileLevel enumeration indicates the state of a file:
- Published: 0
- Draft: 1
- Checkout: 2
Additional property CheckOutType shows if a file was checked out, and the checkout type:
- Online - The file is checked out for editing on the server: 1
- Offline - The file is checked out for editing on the local computer: 2
- None - The file is not checked out: 255 (don't ask me why the value is 255 and not 3 :))
So the idea is to use document updated trigger and check the status using properties above.
The trigger is pretty simple:
Then we need to get the actual status with HTTP call:
As soon as we have our data available, we can check the status and make the decision if the flow should continue:
Now the "Yes" branch indicates that our file was updated and checked out and we can perform further action on that file.