0
votes

My requirement is to get all the users from the sharepoint list item (person or group field) and assign [Read] permissions to different document libraries. As it has multiple users, on list item update, Is it possible to compare the before and after properties of person or Group field and add/remove permissions of the newly added/removed user?

Currently on item update, I am removing all the existing user permissions and adding them back on item update. I don't even know whether the person or group field has been modified.

1

1 Answers

0
votes

You can test if your column have changed during the ItemUpdating event. Inside SPItemEventProperties you can find Property called AfterProperties. When working on the ItemUpdating you can use BeforeProperties or just use properties.ListItem both of them store the original value.

So if you want to test if anything has changed inside your column you might use following code:

if (properties.ListItem["customColumn"] != properties.AfterProperties["customColumn"])
{
}

But since you have the multi-value user field this won't wokr because these collections return generic objects, which you will have to convert to something comparable (for example by using ToString() method).

Try something following:

 if(properties.ListItem["column"]?.ToString() != properties.AfterProperties["column"]?.ToString()) 
 {
 }

Let me know if that helps.