0

I have created a custom list definition with a lookup field using Visual Studio. Everything is working perfect.

After that I created a site definition using Visual Studio and added this custom list to the site definition using the onet.xml like this:

<List FeatureId="128987af-fc74-4707-9b4f-79b0a342b352" Type="10000" Url="Lists/Risiko_mgmt/AllItems.aspx" QuickLaunchUrl="/Lists/Risiko_mgmt/AllItems.aspx" Title="Ereignisse"></List>

Deployment was successful but when I create the site definition it says invalid fieldname pointing to the GUID of the lookup field.

What am i doing wrong?

Thank you.

1 Answer 1

0

Creating lookups through GUIDs is unreliable and can break if you migrate or upgrade Content Databases. Here is a Powershell script that will fix the lookup for you:

Add-PSSnapin Microsoft.Sharepoint.Powershell
Function Fix-LookupColumn ($webURL, $listName, $columnName, $lookupListName)
{
  #Get web, list and column objects
  $web = Get-SPWeb $webURL
  $list = $web.Lists[$listName]
  $column = $list.Fields[$columnName]
  $lookupList = $Web.Lists[$lookupListName]

  #Change schema XML on the lookup column
  $column.SchemaXml = $column.SchemaXml.Replace($column.LookupWebId.ToString(), $web.ID.ToString())
  $column.SchemaXml = $column.SchemaXml.Replace($column.LookupList.ToString(), $lookupList.ID.ToString())
  $column.Update()

  #Write confirmation to console and dispose of web object
  write-host "Column" $column.Title "in list" $list.Title "updated to lookup list" $lookupList.Title "in site" $web.Url
  $web.Dispose()
}

Fix-LookupColumn -webURL http://Site -listName "ListName" -columnName "ColumnName" -lookupListName "LookupList"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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