#FlowNinja hack 78 - modifying Modified By and Modified time with Microsoft Flow

rodion-kutsaev-59544-unsplash.jpg

In this quick blog post - we talk about how we can tweak the “Modified By” user field and “Modified” datetime field in SharePoint list and document libraries using Microsoft Flow.

This technique follows the very detailed article by MVP Andrew Koltyakov on LinkedIn - he describes how to call it with C#, JSOM and REST. He also has detailed examples of every possible field and what format you’ll need to run this with.

I’m calling it with Flow. So to see the full explanation you’ll have to read Andrew’s article ;-)

Also, before you read any further - please repeat the title of the blog post loudly, really fast 3 times.

Plan

  • Requirements - why do we want this?

  • Call ValidateUpdateListItem method with Flow


Requirements - why do we want this?

  • You have updated a list item - you don’t really want the items to all say “Updated by System Account”.

  • You’ve copied a bunch of files but you don’t want it to all say “Modified (now)”.

  • You want to modify the item but you don’t want to create a new version.

  • You uploaded a file but you don’t want to have two versions when you tweak the metadata.

  • You wanted the update to tell you if the validation fails some SharePoint list item rule (this method will return a validation array object)

I need this. You also need this.

I don’t think we need to explain why you really really need this.


Flow

Here we have an item - modified a few seconds ago by me.

We want to update two values - the Modified By and the Modified (date time) fields.

Note the User is a JSON object that needs to be serialized by string() inside another JSON object.

The modified date is a date value, formatted to the “g” format. This format is usually MM/dd/yyyy HH:MM AA in EN locales. It is DIFFERENT if your environment has different locales. You can use “g” as date time string format to get the correct one for your locale.

Updates: 2020-06

Instead of “g”, we can also use 'yyyy-MM-dd hh:mm:ss' which seems to work for all locales. More reading on this issue.

Also, Mikael pointed out we should use bNewDocumentUpdate: true to avoid creating a new version.

Here is when it runs. Notice the Editor field is escaped JSON string.

Result

The modified date is now Feb 18, 2018!

And the user is someone else - my minion Gandalf.

Extra Date Time Note

Here is an example of using addDays(utcNow(), -365, ‘g’)
So this date is a year before right now, with the ‘g’ date formatting string.

https___pbs.twimg.com_media_Dzr4RL3U8AAAEa2.png