This one is a common task, something I've set up a quadrillion times with workflows and event receivers in SharePoint over the past decade or so. And now the time has come to using Microsoft Flow.
The scenario is that when a file is created, you have a piece of business logic which should set metadata on the file. It could be a status flag, a serial number - the business cases are many and diverse.
Read on, young apprentice (you know who you are :) )
First set up a trigger using When a file is created (properties only), and the action Update file properties. Simple right?
When you create a new document from the New button in the library this is what happens:
The update fails, as the file is locked by the Office application creating the file. This is regardless if you use for example Word online or the desktop version. If you however upload a document this does not happen.
The solution? If you have read my recent post Disable Event Firing when Flow updates a SharePoint list item, you might already know.
You need to update the properties using SystemUpdate. Please refer to my previous post on how to set this up.
Note: If you use the XML version, it always works. If you use the ValidateUpdateListItem version, you can still get issues if the Flow connection runs as a user different from the one creating the file.
By switching the Update file properties action with a Send an HTTP request to SharePoint, all runs just fine.
Happy flowing!