I am working on an Event Receiver for my SharePoint farm 2013. now i have a site column of type "People or Group", and this site column can hold User Name/s OR group names.
so inside my Event Receiver code, i want to check for the item type an based on it assign the site column to a varaible as follow:-
SPListItem currentItem = properties.ListItem;
string initial = "";
SPUser orderOwner = null;
if (currentItem.ContentType.Name.ToLower().Contains("p"))
{
initial = "P";
orderOwner = currentItem["ProjectOwner"] != null ? (SPUser) currentItem["ProjectOwner"] : null;
}
else if (currentItem.ContentType.Name.ToLower().Contains("s"))
{
initial = "S";
orderOwner = currentItem["SalesOwner"] != null ? (SPUser)currentItem["SalesOwner"] : null;
}
else if (currentItem.ContentType.Name.ToLower().Contains("c"))
{
initial = "C";
orderOwner = currentItem["CancellationOwner"] != null ? (SPUser)currentItem["CancellationOwner"] : null;
}
now my above code will work as long as the orderOwner
variable is holding an SPUser, but if the related field (ProjectOwner,SalesOwner,CancellaltionOwner) is holding an SPGroup my code will break. so i am not sure how i can have a variable type inside my Event Reciever, which can hold an SPUser or SPGroup ??