top of page
  • Writer's pictureStephen Port

Stop the Pesky Pending Problem when updating an item with Approvals on.

Approvals in SharePoint are a great way to make sure changes are approved before being submitted, but what happens if you need to update a workflow's approval status when running Power Automate back to the original state e.g. Rejected/Approved.


In this very specific scenario, I had to build a workflow for a client that would update a document's metadata to the metadata of the 'Parent' files in the library. They could also tag the document with more than one parent or related file.


That was pretty fun to build. Essentially, I would go off and grab the metadata for all files tagged against the document, get the unique values and update the current files metadata.


The problem was that the approval status would change to pending which isn't what we wanted. It needed to stay as the original Approved/Rejected.


The first thing I had to do was to get the changes for the file since we ran the workflow. In other words, the version before we changed the files data.

I only wanted the previous version so I used the below for the Since value

Add(int(triggerBody()?['{VersionNumber}']),-1)

This however doesn't actually get you any of the metadata, just a list of true/false values if the field has changed. As such we need to use a HTTP request to get the metadata of the version.

The important part here is that you need to get the version ID which isn't the version number so make sure you select the below SinceVersionId from the dynamic fields.

The next step is to Parse the JSON of the output of the HTTP request. We only need the ModerationStatus so use this as your Schema. This is important to note. If you try and use the whole output from the previous section it will fail as some of the values are null.

{
    "type": "object",
    "properties": {
        "d": {
            "type": "object",
            "properties": {
                "OData__x005f_ModerationStatus": {
                    "type": "integer"
                }
            }
        }
    }
}

Last thing is to get the moderation status ID. This is an integer

0 = Approved

1 = Rejected

2 = Pending



The last thing to do is to set the Approval status on the item based on the value we have got. To do this however, you need to get the ETag for the file. So first, you need to get the file metadata and then build out the conditions to set the approval status as per the below

And there you have it. I have built a workflow that allows me to update the file properties from multiple parent documents and apply the metadata without the need to re-approve the file.

40 views

Related Posts

See All

Comments


bottom of page