MS Flow - How do I achieve “Automatically reject the document if it is changed before the workflow is completed.”?

sharepoint.stackexchange https://sharepoint.stackexchange.com/questions/286333

  •  17-02-2021
  •  | 
  •  

Question

I am new MS Flows and trying to achieve the same SP2010 OOB approval WF feature... Reject document if it is changed before the workflow is completed. I do see an action "Get changes for an item or a file (properties only)". Looks like this identifies only the property changes not the file change. What action I need to use to reject the document if file content is changed when workflow is in progress?

Was it helpful?

Solution

Having analyzed the versions' history of SPO documents from the output of a [Send an HTTP request to SharePoint] action in MS Flow, I think, we can use MediaServiceMetadata, which contains lastStreamUpdateTime, for checking whether the File/Document Content or column values are changed.

In my testing, I found that lastStreamUpdateTime is updated only when the file's content is changed.

Here's is a sample of MediaServiceMetadata property value:

 "MediaServiceMetadata": "{\"ctag\":\"\\\"c:{be827ad2-e597-441b-9a92-7df9a61556f3},6\\\"\",\"generationTime\":\"2020-11-02T02:18:58.3346095Z\",\"lastStreamUpdateTime\":\"2020-11-02T02:18:58.3346095Z\",\"modules\":[{\"module\":\"AIPLabelExtract\",\"version\":1},{\"module\":\"OfficeBundleGeneration\",\"version\":1}],\"officeBundle\":{\"ctag\":\"\\\"c:{be827ad2-e597-441b-9a92-7df9a61556f3},6\\\"\",\"fatalError\":false,\"version\":\"4.1342833475\",\"generationTime\":\"2020-11-02T02:18:57.3814502Z\",\"generationReason\":\"AnalysisPipeline\"}}"

I've also noticed that there is a little delay between the timestamp the version is created and the timestamp value in lastStreamUpdateTime. Most likely some background process updates lastStreamUpdateTime.

High-Level Concept of the Flow steps

  1. When a document is uploaded to the SPO Library, MS Flow kicks in for trigger [When an item is created]

  2. At the beginning of the Flow, store the Flow start timestamp into a variable

  3. Initialize a couple of more variables as shown in the screenshot.

  4. Add [Start and wait for an approval] action with options Approve, Reject, Cancel etc

  5. Once the document review outcome is received in the Flow, process Reject and Cancel as normally you would

  6. If the outcome is Approve, verify if the Document content was changed by comparing the Flow starting timestamp with the value of lastStreamUpdateTime in MediaServiceMetadata,
    that is, lastStreamUpdateTime > Flow Starting Timestamp

  7. If the document content was changed after the flow was started, set it's status to "Edited Prior Approval" or whatever suits the business

See the screenshots and further explanation below

enter image description here

Detail 1

enter image description here

Detail 2

enter image description here

Detail 3

enter image description here

Expressions 1, 2, 3

1.

split(
replace(replace(replace(replace(replace(replace(
 string(body('Parse_JSON')?['d']?['results'][0]['MediaServiceMetadata']), '[', ''), ']', ''), '{', ''), '}', ''), '"', ''), '\',''), ',')

2.
item()

3.
if( greater( length(body('Filter_array')),0), replace(body('Filter_array')?[0], 'lastStreamUpdateTime:', ''), variables('varStartTimestamp'))

Detail 4

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top