Do i need to Issue ListItem.Update(), when i am executing these commands ( ListItem.ResetRoleInheritance() + ListItem.RoleAssignments.Add() )

john john 956 Reputation points
2020-10-23T09:34:03.343+00:00

I am working on a remote event receiver inside SharePoint online custom list. now inside the RER i am getting the item been updated, then reset its role inheritance + add users to the item permission, as follow:-

projectItem.ResetRoleInheritance();
projectItem.BreakRoleInheritance(false, false);
projectItem.RoleAssignments.Add(oUser, new RoleDefinitionBindingCollection(context) { readerDef });
FieldUserValue[] approvers = projectItem["Approvers"] as FieldUserValue[];
                    foreach (FieldUserValue user in approvers)
                            {
                              User oUser2 = context.Web.EnsureUser(user.LookupValue);
                              context.Load(oUser2);
                              context.ExecuteQuery();
                              projectItem.RoleAssignments.Add(oUser2, new RoleDefinitionBindingCollection(context) { contributeDef });

                             }

now i thought to get the ListItem.ResetRoleInheritance() + ListItem.RoleAssignments.Add() working i need to execute ListItem.Update() at the end.. but based on my test the ListItem.ResetRoleInheritance() + ListItem.RoleAssignments.Add() will be applied without having to execute ListItem.Update().. so is my assumption correct? Thanks

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,563 questions
0 comments No comments
{count} votes

Accepted answer
  1. Amos Wu-MSFT 4,051 Reputation points
    2020-10-26T05:48:49.063+00:00

    Yes,you are right,there is no need to add ListItem.Update() when you use ListItem.ResetRoleInheritance() + ListItem.RoleAssignments.Add().
    ListItem.Update() needs to be used when submitting the modified properties of the listItem.
    Official document about ListItem.Update() for your reference:

    https://learn.microsoft.com/en-us/previous-versions/office/sharepoint-server/ee536748(v=office.15)


    If the response is helpful, please click "Accept Answer" and upvote it.
    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.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.