HI All,
Today We will see about getting the value of a LookUp field in a Synchronous Event.
There is a major difference in getting the value of the same when the following two things are called.
1)properties.ListItem
2)properties.AfterProperties
For the first , properties.ListItem
We have to make call like this,
SPFieldLookupValue prevItemValue = new SPFieldLookupValue(properties.ListItem["FieldName"] as string ?? string.Empty);
string FieldNameListItem = prevItemValue.LookupValue;
And for the second, properties.AfterProperties
SPFieldLookupValue newItemValue = new SPFieldLookupValue(properties.AfterProperties["FieldName"] as string ?? string.Empty);
int str1 = newItemValue.LookupId;
SPList targetList = properties.Web.Lists["Target List"];
SPListItem targetItem = targetList.GetItemById(str1);
string FieldNameAfterProperties = targetItem["ParentField"].ToString();
On seeing the piece of code for properties.ListItem we can easily understand the logic how it works.
For the second one, a small detour has been done to get the value.
On calling properties.AfterProperties we only get the Id of the particaular item and the value is missed. So for getting the value of that field in After properties we have to query the master list,s master column.
Hope you all understand. Please drop your queries for any further clarification.
Thanks for your Time.. See you on my next post...
Today We will see about getting the value of a LookUp field in a Synchronous Event.
There is a major difference in getting the value of the same when the following two things are called.
1)properties.ListItem
2)properties.AfterProperties
For the first , properties.ListItem
We have to make call like this,
SPFieldLookupValue prevItemValue = new SPFieldLookupValue(properties.ListItem["FieldName"] as string ?? string.Empty);
string FieldNameListItem = prevItemValue.LookupValue;
And for the second, properties.AfterProperties
SPFieldLookupValue newItemValue = new SPFieldLookupValue(properties.AfterProperties["FieldName"] as string ?? string.Empty);
int str1 = newItemValue.LookupId;
SPList targetList = properties.Web.Lists["Target List"];
SPListItem targetItem = targetList.GetItemById(str1);
string FieldNameAfterProperties = targetItem["ParentField"].ToString();
On seeing the piece of code for properties.ListItem we can easily understand the logic how it works.
For the second one, a small detour has been done to get the value.
On calling properties.AfterProperties we only get the Id of the particaular item and the value is missed. So for getting the value of that field in After properties we have to query the master list,s master column.
Hope you all understand. Please drop your queries for any further clarification.
Thanks for your Time.. See you on my next post...
No comments:
Post a Comment