tags:

views:

65

answers:

1

Hi,
I have a list named "Projects" which has a number column named "Job Number", I have attached an ItemAdded event handler to Job Number to increment.

Within the Projects list, I created a look up column named "Original Job" which looks up the value from the column Job Number.

When I click new item, I see the drop down values of all my Job numbers but when I choose one and click create item, there is no value, shows empty.

Here is my code:

SPList lookupList = currentSite.Lists["Projects"];
SPField lookupField = lookupList.Fields["Job Number"];
projectList.Fields.AddLookup("Original Job", lookupList.ID, false);
SPFieldLookup lookup = (SPFieldLookup)projectList.Fields["Original Job"];
lookup.LookupField = lookupField.InternalName;
lookup.Update();

Here is an image

http://pic100.picturetrail.com/VOL783/3746656/21927341/372654494.jpg

Can someone please explain why this occurs?

A: 

YOu need to call the Update method of the Item you're itself, not the SPFieldLookup lookup variable, your code should look like this:

protected override ItemAdded(properties)
{
  var item = web.Lists[properties.ListId].GetItemById(properties.ListItemId);
  if (item != null)
  {
    if (item.Fields.ContainsField("Job Number"))
    {
      // get selectedValue from the original job??
      item["Job Number"] = selectedValue; 
      item.Update(); 
      //or item.SystemUpdate();
    }
  }
}
Colin
My Job Number is fine.My lookup column "Original Job" is not displaying any values.Original Job is suppose to be a look up column to Job number.When I click create item, I see the drop downlist of all the job number but only when I click create, the original job doesn't display any values.
curiousUser