[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 551
  • Last Modified:

Reading Lookup value within ItemAdding method

Hi,

how can I read the Lookup value within the ItemAdding method.  At the moment, I am getting something like the following: 4#

thanks
0
yechan
Asked:
yechan
  • 4
  • 3
1 Solution
 
abhitrigCommented:
Try this:
SPFieldLookupValue itemValue = item["FieldName"] as SPFieldLookupValue;
int id = itemValue.LookupId;
string value = itemValue.LookupValue;

This would help: http://sharepointcodeblock.blogspot.com/2008/07/properly-populating-and-retrieving.html
0
 
yechanAuthor Commented:
thanks for the link.  Can you please tell me where "item["FieldName"]" comes from?  
0
 
abhitrigCommented:
Use properties.AfterProperties["YourColumnName"] instead of item["FieldName"].
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
yechanAuthor Commented:
I have done what you suggested but itemValue evaluates to null.

Below is what I have:

SPFieldLookupValue itemValue = properties.AfterProperties["Section"] as SPFieldLookupValue;

properties.AfterProperties["Section"] returns 4.

Section is a column inside a list.  Section is lookup column to a another list called "Section".  Maybe some kind of naming conflict?
0
 
abhitrigCommented:
What kind of data does the section list contain? Also which column of the Section list are you using as the lookup? Is it a multi-select column by any chance?


0
 
yechanAuthor Commented:
Good morning,

the section list contain just contains plain old text data.  When I changed the lookup properties of section from "SectionName" to "ID", I now know where the value of 4 is coming from.  Must be some internal ID thing.  Not sure but I suspect that the "SPFieldLookupValue" is there to aid in getting the value and text of a particular lookup item.
0
 
yechanAuthor Commented:
dead question
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now