2
votes

I'm new to Sharepoint 2010 and I'm currently trying to create lookup field, add it to content type and add it to the list via Visual Studio 2010 SharePoint project. But I experience some weird problem.

I've defined a lookup field in the following way:

  <Field ID="{2A5567B7-1175-4E26-A4ED-382E4744D17A}" Type="Lookup" Name="SomeLookupField" List="Lists/SomeList" ShowField="ItemName" DisplayName="Some Field" Group="Custom Group" ReadOnly="TRUE" />

Then I added it to ContentType via FieldRef element. And, finally, List Definition contains the same element in Schema.xml

It works fine until I'm trying to save my site as template. Sharepoint fails to export the site and displays error:

Microsoft.SharePoint.SPException: Error exporting the site field named "SomeLookupField". at Microsoft.SharePoint.SPSolutionExporter.ExportFields(SPFieldCollection fields, String partitionName)

That is caused by the error:

SPSolutionExporter: System.FormatException: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx). at System.Guid..ctor(String g) at Microsoft.SharePoint.SPSolutionExporter.GetFieldSchemaXml(SPField field, SPWeb web, Boolean isFieldFromWeb, Boolean removeSealedAttribute) at Microsoft.SharePoint.SPSolutionExporter.ExportField(SPField field, SPWeb web)

Playing around I found out that lookup field ID should not contain curly brackets and be like the following:

<Field ID="2A5567B7-1175-4E26-A4ED-382E4744D17A"

After I changed it export start working fine. But redeploy from Visual Studio is broken now as it doesn't delete the field while removing old feature and fails on updated feature activation with the error:

Error occurred in deployment step 'Activate Features': The field with Id {2A5567B7-1175-4E26-A4ED-382E4744D17A} defined in feature {235313d2-4091-4655-8b35-70b3ad31b9f4} was found in the current site collection or in a subsite.

I wonder what can be wrong with my lookup field definition? What is a valid format of defining lookup fields?

1

1 Answers

2
votes

Found the solution. Lookup column definition must have overwrite attribute set to 'TRUE'. Blogged about it here