For a couple of weeks back, when we had to check if a document was approved and use Flow we had to do some difficult stuff with the old workflow engine, writing to a process list and start Flow on that process list etc. etc.
It was working but not very efficient. But then the http request Flow action was born.
My life flourished…………………………………………………………Sorry, I went off ?
So what is the case. Very simple, we have two document libraries, each in a seperate sitecollection. When a document has been approved (not with an approval flow, just approved through the UI), the document must be copied to another sitecollection including the metadata. And if the document has been rejected an email has to be sent to the moderator.
Let’s start creating the following flow:
First we have to trigger when a file has been created or modified. I use the properties only action, because we just need the properties of the file:
And now comes the trick. We get the version history of the file with a httprequest action:
_api/web/lists/getbytitle('Documenten')/items( <ID> )/versions?$top=1
and return the results in a JSON format:
Headers:
key : accept, value : application/json;odata=nometdata
($top=1 means that we just need the data from the last version, in other words the latest version.)
The result in JSON format has all the metadata of the file. For this solution I only needed two values, so I get them separately. But you can also use the data request html table action for example to add the results to a html table format.
So let’s get the moderation status value, I use the initialize variable action and the following expression:
first(body('HTTP_Request_-_Get_versions')['value'])?['OData__x005f_ModerationStatus']
You can lookup the field name in the JSON data returned by the http request action.
And we need the moderation comments:
first(body('HTTP_Request_-_Get_versions')['value'])?['OData__x005f_ModerationComments']
From this point it’s straight forward, check the moderation status value with a condition:
Just for your information:
- #0 The item is approved
- #1 The item has been denied approval
- #2 The item is pending approval
- #3 The item is in the draft or checked out state
If it’s equal to zero, the file is approved and now we have to copy the file.
Let’s get the default copy file action, copy the file and we are ready.
NO, no document properties. ? hmm straight forward I said…..
No worry, I found the solution. We have to get the file contents:
Create a new file with the retrieved file contents:
And finaly update the file properties:
And now the file has been copied with all the properties.
Leaves us to the step, sending an email when the file has been rejected.
First check the moderation status:
And perform the send email action and here is were we use the moderation comment:
And we’re finished, a simple approval follow up solution with flow!