Janika

Trigger a Microsoft Flow when A document is Checked In

I made a flow for a Document Library in SharePoint Online.

The flow:

  1. Waits for a document in the library to be checked in
  2. Sends an email to the manager of the user who checked in the document
  3. Waits for the manager to approve or reject
  4. If approved, update the "Approval Status" metadata of the document to "Approved"

This sounds like something that'd be easy to do out of the box, but the trigger for "When a document is checked in" doesn't exist for Document Libraries, only for lists.

Here's how I did it: First, I did some looking around for how others have solved this and managed to find this helpful forum post.

In a blank flow, I added:

  1. When a file is created or modified (properties only)
  1. Get file metadata using path

Next I added a check to see if the doc is already approved. If it is, terminate the flow. 3. Condition

  1. Send an HTTP request to SharePoint
_api/web/getFileByServerRelativeUrl('/sites/YOURSITEHERE/@{triggerOutputs()?['body/{Path}']}@{triggerOutputs()?['body/{FilenameWithExtension}']}')/checkOutType

Make sure you manually select "Folder path" and "File name with extension" from the dynamic content list, leaving them from the copy/pasted code triggered an error in the flow checker

  1. Parse JSON
{
    "type": "object",
    "properties": {
        "d": {
            "type": "object",
            "properties": {
                  "CheckOutType": {
                        "type": "integer"
                   }
               }
        }
}
}
  1. Get user profile (V2)
  1. Get manager (V2)
  1. Start and wait for an approval
  1. Next is another condition.

And finally If no sends a copy of the email above but informing of rejection instead of approval.

This flow took a fair amount of trial and error, but this final version works alright. I check to see what the approval status is early in the flow because of my current issue, which is that this flow triggers twice. Still working on fixing that properly, but the flow cancels itself if the doc is already approved so not a big deal I guess.

#check in #dynamic content #microsoft flow #sharepoint #trigger on check in #workflow