0

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?

9
  • Could you clarify what tasks the current instance of the MS Flow is waiting for? Is it waiting for an approval? I that case, you probably could lock the document from within the MS Flow so that no one can edit it prior approval process is complete. – Matiur Rahman Oct 29 '20 at 20:58
  • 1
    Here is an article that talks about locking the file when Flow starts and unlock after it ends. However, you could check version changes using MS flow as well – Matiur Rahman Oct 29 '20 at 21:22
  • Yes, it waits for an approval. Locking the file looks like a workaround. Isn't there any direct way? How do I ensure the version change is only due to the file content change not for any other properties? – san Oct 29 '20 at 21:34
  • There is no such action in Power Automate, you will have to use a workaround for this request. A flow instance does not check for the changes on the object during the Approval task. If you want to keep the version number of the document, locking it will be the ideal solution. – Chelsea_MSFT Oct 30 '20 at 7:44
  • Version number change is ok.. but should be able to identify the change is due to file content change not because of other properties of file. If yes, can you please explain or provide an example. – san Oct 30 '20 at 10:52
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.