List versioning detect field level changes
-
09-12-2019 - |
Question
I need to detect changes with each on each item update, )but i don't want to use the before, after properties )
My question is:
If i enable list versioning can i diff 2 versions to detect changes, what would be the performance impact? (storage, versions retrieval)
Thanks!
Solution
It depends on which technique you plan to use:
Event Handlers - use ItemUpdating having properties object contains the collections BeforeProperties and AfterProperties that helps you to find out what has changed for your item, i.e. compare properties.BeforeProperties[].ToString() with properties.AfterProperties[].ToString(). You can also modify the value of the fields in AfterProperties to affect what is actually stored in the list.
SPD Workflows - use the Activity "Wait for field change" and the you could compare the 2
If you need to handle it across versions use something similar to
if ((item.Versions!= null) && (item.Versions.Count > 0))
{
SPListItemVersionCollection versions = item.Versions;
//work with through the colection
}