Update CreatedBy, ModifiedBy,Created, Modified in SharePoint list

Posted by

In this concise blog post, we explore a method to customize the “Modified By” user field and “Modified” datetime field in SharePoint lists and document libraries using Microsoft Power Automate.

Why would you need that?

Customizing the “Modified By” user field and “Modified” datetime field in SharePoint using Microsoft Flow can be necessary in various scenarios. Here are some reasons why you might need to perform such customization:

  1. Preserving User Accountability:
    • In default SharePoint behavior, updates often display as if they were made by the system account. Customizing the “Modified By” field ensures that the actual user making the update is correctly reflected, maintaining accountability and transparency in content modifications.
  2. Avoiding Unwanted Versioning:
    • When making changes to SharePoint items or uploading files, the system may automatically create new versions. In certain cases, you may want to update metadata or tweak content without generating additional versions. Customizing the “Modified” datetime field helps in controlling version creation.
  3. Fine-Tuning Metadata Updates:
    • In scenarios where you need to modify items but do not want to trigger a new version, customizing the fields allows for fine-tuning metadata updates without impacting version history.
  4. Validation of SharePoint List Item Rules:
    • The technique of customizing these fields using Flow includes a method call, ValidateUpdateListItem, which can return a validation array object. This can be crucial for ensuring that the update adheres to SharePoint list item rules, providing feedback in case of validation failures.
  5. Flexible Date Formatting:
    • Customizing the date format allows for flexibility in displaying the “Modified” datetime field according to specific locale preferences. This ensures that the date and time information is presented in a user-friendly and contextually appropriate manner.
  6. Dynamic Content and Workflows:
    • By leveraging Microsoft Flow, you can create dynamic and automated workflows that update SharePoint fields based on specific conditions, ensuring that your content stays accurate and relevant.

Let’s try doing that using Power Automate

  1. Initialize Variables:

Initialize two variables: ModifiedByUser (String) and ModifiedDateTime (String).

2. Set Variable – ModifiedByUser:

Set the value of the ModifiedByUser variable. This might involve serializing a user object to a JSON string.

[{'Key':'i:0#.f|membership|vivek.sheel@theta.co.nz'}]

Set Variable – ModifiedDateTime:

Set the value of the ModifiedDateTime variable. Use expressions to format the current date and time. For example:

formatDateTime(utcNow(),'dd/MM/yyyy HH:mm')

Adjust the format based on your requirements.

Make an HTTP call to SharePoint with the following parameters

Uri:

_api/web/lists/GetByTitle('YourList')/items(ID of the item)/validateUpdateListItem

Body:

{
"formValues":[
{"FieldName":"Editor","FieldValue":"@{variables('ModifiedByUser')}"},
{"FieldName":"Modified","FieldValue":"@{variables('ModifiedDateTime')}"}
]
}

In the example above, I want to update the item with an ID of 11.

Now let’s test the flow

Leave a Reply

Your email address will not be published. Required fields are marked *