Logo
  • Contact form
  • Events & slides
  • Buy me a snack
Logo

Events & slides

Buy me a snack

Contact form

Data privacy policy

About

This blog is made with ♥️ on Notion and made public with Super.so. Rocket icon created by RIkas Dzihab - Flaticon.

RedditLinkedIn
👋🏻
/
📝
All Blogs
/
👤
Change the author field value in SharePoint Online
👤

Change the author field value in SharePoint Online

Table of contents

  • Introduction
  • Actions
  • Variables
  • Getting the entity name
  • Find the Id for the Author Field
  • Lookup the user with the corresponding SharePoint user Id
  • Unlock the Author field
  • Overwrite the Author field value
  • Lock the Author field
☝
TL;DR - The sharepoint author field is not editable from the UI of SharePoint Online. As it is simply “another” person column, you can update it with Power Automate. You will need to unlock it first, which is easier than you think.

Introduction

I recently found out that one can modify an item's or file's author in SharePoint, along with other normally read-only fields. I've tested this with an item's Author and the FirstPublishedDate for news in SharePoint.

Even after changing the author, the SharePoint Lists' feature that only allows the item's author to edit it still works.

In my situation, I had to transfer list items from SharePoint into a new format, while preserving the original authors and their editing rights. This is why I developed a flow to serve as a subsidiary to a larger migration flow.

👀
The code snippets below already contain all the variables in paste-in-ready format. You can see used expressions as „@{….}“. If you want to use your own expressions and variables, feel free to change them.

Actions

As this is a child flow, I have a manual trigger with inputs referencing the variables below and a „Respond to flow or app“ - action at the end.

Variables

I strongly recommend using variables. I have created three to help with the flow.

  1. intItemId - Integer - This holds the item ID where the author's information needs to be updated.
  2. strUserEmail - String - This is the user E-Mail that will replace the current author.
  3. strLibraryId - String - This is the unique ID of a library or list in SharePoint Online.
image

Getting the entity name

Getting the entity name is needed to write back the new author to the item.

Uri
_api/web/lists(guid'@{variables('strLibraryId')}')/?$select=ListItemEntityTypeFullName
image

Find the Id for the Author Field

Every field in SharePoint has a GUID (Globally Unique Identifier), which is used to modify the field. If you already have the GUID for the author field, you can skip this step. It should be consistent across SharePoint. Knowing this will make it easier to manage other fields without the need to verify each time.

Uri
_api/web/lists(guid'@{variables('strLibraryId')}')/fields?$filter=EntityPropertyName eq 'Author'
image

Lookup the user with the corresponding SharePoint user Id

The Author field does not accept a simple E-Mail address. That is why you will need to translate the users E-Mail address to a SharePoint unique user id.

Uri
_api/web/siteusers/getByEmail('@{variables('strUserEmail')}')
image

Unlock the Author field

Since the author field, among others, is technically locked and read-only, you'll need to unlock it to alter the author of a specific list item.

image

Overwrite the Author field value

In this step we use the users SharePoint user id to update the author.

image

Lock the Author field

Once you've made all the necessary changes, remember to lock the field again. In my case, each change requires unlocking and relocking the field. However, it's also possible to keep the field unlocked while making changes and only lock it once all changes are complete.

image
Uri
_api/web/lists(guid'@{variables('strLibraryId')}')/fields(guid'@{first(body('Send_an_HTTP_request_to_SharePoint_-_Find_Author_Field_Id')?['d']?['results'])?['Id']}')
Header
{
  "Content-Type": "application/json;odata=verbose",
  "IF-Match": "*",
  "X-HTTP-Method": "PATCH"
}
Body
{ '__metadata': { 'type': 'SP.Field' }, 'ReadOnlyField': false }
Uri
_api/web/lists(guid'@{variables('strLibraryId')}')/items(@{variables('intItemId')})
Header
{
  "Content-Type": "application/json;odata=verbose",
  "IF-Match": "*",
  "X-HTTP-Method": "PATCH"
}
Body
{ '__metadata': { 'type': '@{body('Send_an_HTTP_request_to_SharePoint_-_Entity_Name')?['d']?['ListItemEntityTypeFullName']}' }, 'AuthorId': @{body('Send_an_HTTP_request_to_SharePoint_-_Lookup_User')?['d']?['Id']} }
Uri
_api/web/lists(guid'@{variables('strLibraryId')}')/fields(guid'@{first(body('Send_an_HTTP_request_to_SharePoint_-_Find_Author_Field_Id')?['d']?['results'])?['Id']}')
Header
{
  "Content-Type": "application/json;odata=verbose",
  "IF-Match": "*",
  "X-HTTP-Method": "PATCH"
}
Body
{ '__metadata': { 'type': 'SP.Field' }, 'ReadOnlyField': true}