Thursday, June 13, 2013

LookUp Column Re-mapping to List (Get information from is null)

When you create a list with lookup columns using VS 2010. You may find all Lookup column missing there mapping to parent list.

"Get information from" will be null on Column settings page.

Use Below code to remap those fields on Feature activated:

private static void UpdateLookUpColumn(SPWeb web, String updateToList, String parentList, String columnName)
SPList list = web.Lists.TryGetList(updateToList);
SPList listMain = web.Lists.TryGetList(parentList);
SPField field = list.Fields[columnName];
String schemaString = field.SchemaXml;
XDocument fieldSchema = XDocument.Parse(schemaString);
XElement root = fieldSchema.Root;
// XAttribute attrList = root.Attribute("List");
root.SetAttributeValue("List", listMain.ID);
field.SchemaXml = root.ToString();

Will be writing the powershell Script for same soon...

No comments:

Post a Comment

SharePoint document metadata not updating

I faced a weird issue today, Metadata for document which has lookup column was not updating even after saving the item. There was no erro...