So I'm trying to accomplish this kind of functionality on my SharePoint 2010 list:
I have a field of type choice in my list, which has 7 values and i want users not to be able to change the value of that field from values 2,3,4,5,6,7 to value 1.
I've written an event receiver for that list, here's my code:
public override void ItemUpdated(SPItemEventProperties properties)
{
base.ItemUpdated(properties);
string beforeStatus = properties.BeforeProperties["Status"].ToString();
string afterStatus = properties.AfterProperties["Status"].ToString();
if (beforeStatus != "1stValue" && afterStatus == "1stValue")
{
properties.Cancel = true;
properties.ErrorMessage = "This isn't allowed.";
}
}
I've tried using both ItemUpdated
and ItemUpdating
event receivers, when I was debugging I saw that the event receiver get's called as it should be, but beforeStatus
and afterStatus
is getting null
from the item in both cases.
So, how can I get the values of the item's field before and after updating correctly? Thanks in advance!
Note: the field's internal and display names are both Status
.