How to update ModifiedBy field in SharePoint Online document using Graph

José Ángel Salmerón 45 Reputation points
2024-05-22T15:31:10.2033333+00:00

Hello,

i would like to know if it's possible to update ModifiedBy (Editor) field in a document uploaded into a DocumentLibrary of a Site in SharePoint Online using MS Graph.

I've tried these approaches:

  1. Using 'patch' method of a DriveItem: i can modify 'Name' property but nothing happens with 'LastModifiedBy' property.
  2. Using ListItem.Fields.Patch method: i receive next exception:

Microsoft.Graph.Models.ODataErrors.ODataError: Field 'Editor' is read-only

Is it possible somehow to update this value?

If not, is there any workaround i can use?

The need of doing it is simple: i've a client application that execute some operations on certain documents. I dont want to have 'SharePoint App' as value of 'Modified By' field, would like to have the actual employee that last modified that document.

Thanks in advance.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,447 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,300 questions
0 comments No comments
{count} votes

Accepted answer
  1. Hitesh Pachipulusu - MSFT 475 Reputation points Microsoft Vendor
    2024-05-22T17:22:15.29+00:00

    Hello @José Ángel Salmerón,Thank you for contacting Microsoft Support.

    Unfortunately, updating the ModifiedBy (Editor) or CreatedBy (Author) field for a document in SharePoint using the Microsoft Graph API is not directly possible. Both of these fields are read-only properties, and the Graph API does not provide a direct way to modify them.

    However, you can consider below workaround:

    1. Custom Field: Create a custom field where you can store the actual employee that last modified that document. If ModifiedBy is equal to SharepointApp then you can store actual employee that last modified that document and if it's not equal store the value that is present in ModifiedBy field. This way, you can differentiate actions taken by different processes without directly modifying the read-only fields.

    Hope this helps.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 33,641 Reputation points Microsoft Vendor
    2024-05-23T02:51:54.59+00:00

    Hi @José Ángel Salmerón,

    As far as I know, there is no such graph api to update a read-only field. As a workaround, I would recommend you to update the ModifiedBy field by rest api ValidateUpdateListItem endpoint.

    https://tenant.sharepoint.com/sites/sitename/_api/web/Lists/GetbyTitle('SPOList')/items(2)/ValidateUpdateListItem()
    
    {  
       "formValues":[  
          {  
             "FieldName":"Author",  
             "FieldValue":"[{'Key':'i:0#.f|membership|user@Tenant.onmicrosoft.com'}]"  
          },  
          {  
             "FieldName":"Created",  
             "FieldValue":"17/1/2021"  
          },  
          {  
             "FieldName":"Editor",  
             "FieldValue":"[{'Key':'i:0#.f|membership|user@Tenant.onmicrosoft.com'}]"  
          },  
          {  
             "FieldName":"Modified",  
             "FieldValue":"17/1/2021"  
          }  
      
       ]  
    }
    
    
    

    User's image

    User's image

    You could also use PowerShell(CSOM/PnP PowerShell) to update SharePoint system field:

    SharePoint Online: Update Created By / Modified By, Created / Modified Field Values using PowerShell


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments