1

I have a sandbox solution in SharePoint . I have created number of site columns, Content Types , list definitions and list instances. Everything has individual feature.

For Ex:

  1. Site column feature (Site feature)
  2. Site content type feature (Site feature)
  3. List destination feature (Web feature)
  4. List instance (Web feature)

I have 3 lookup columns which is provisioned successfully without target list.

Lookup column is configured in Content Type and list instance.

Now, I want to update that lookup field using feature receiver and use lookup value in other list.

What should I Do? My lookup Column element.xml is below.

<Field
ID="{a41ab4e5-a30a-4d99-8e0b-1ab2095d68f2}"
Name="Client"
DisplayName="Client"
Type="Lookup"
Required="TRUE"
Group="Test"
List="{00000000-0000-0000-0000-000000000000}"
ShowField="Title">

How can I replace list ID with {00000000-0000-0000-0000-000000000000}?

  • Once the list and fields are created, load the lookup field (SPFieldLookup) and update the relevant members of the field. Haven't tried it myself. – Prakash - Crow Canyon Dec 24 '15 at 7:24
  • @Prakash-CrowCanyon It is not working , Because i have restriction of sand box solution. – Dipen Shah Dec 24 '15 at 7:28
-1
lstevents = web.Lists["Test"];
fldLookupField = (SPFieldLookup)web.Site.RootWeb.Fields.GetFieldByInternalName("Test");
fldLookupField.SchemaXml = fldLookupField.SchemaXml.Replace("List=\"{00000000-0000-0000-0000-000000000000}\"", string.Format("List=\"{0}\"", lstevents.ID.ToString("B")));
fldLookupField.LookupWebId = lstevents.ParentWeb.ID;
fldLookupField.Update(true);
  • Please add some description about the code. It will be useful for other readers. – Asad Refai Dec 30 '15 at 10:42
  • @Sharepoint. Add some Description and not copy paste the same answer which is given by others. – Dipen Shah Dec 30 '15 at 10:45
0

After a long time, i got the solution of my question . I am sharing with you guys.

lstevents = web.Lists["Test"];
                    fldLookupField = (SPFieldLookup)web.Site.RootWeb.Fields.GetFieldByInternalName("Test");
                    fldLookupField.SchemaXml = fldLookupField.SchemaXml.Replace("List=\"{00000000-0000-0000-0000-000000000000}\"", string.Format("List=\"{0}\"", lstevents.ID.ToString("B")));
                    fldLookupField.LookupWebId = lstevents.ParentWeb.ID;
                    fldLookupField.Update(true);

Add this code to feature activated of List Instances. You can change source id of look up column using this code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.