Search code examples
visual-studio-2013sharepoint-2013content-typesharepoint-listsite-column

"Save Site as Template" Error when using LookupSite columns


After long search on the web i could not figure out why i have been facing wired behaviour today with my SharePoint Site.

I explain,

I have a Site Collection (Blank Site Template) which contains lists content types and site columns.

I have no specific configuration in my web app and no special configuration in my site collection.

When i tried to save Site as Template i got error telling there was a problem with a site field (which was a site colum of type LookUp).

P.s: I have a list based on a content type which is based on that site column

When i removed that site column the operation of template creation succeded, which is kind of wired.

Has anyone faced this before? Can anyone reproduce this issue? and how can i find a workaround to this issue because i need that column to be of type lookup.

Can anyone help me please?


Solution

  • This is a know issue with "Save Site As Template", this operation is not full fidelity Because as you said you can do it if you add the Site colum from SharePoint (from The U.I) and not from Visual Studio...

    Here, you can deduct that this issue is related to Visual Studio and What is happening behind the deployment Action...

    This Problem Has many Workaround Solutions:

    First, you can see the deployment order of your content types and your lists etc. in the .Package file (Design Mode), there you must find the elements in a precise order, for example the Parent SiteColumn and its related content type and list(instance and definition) must come before the child siteColumn (The One containing the lookup) to let SharePoint provison the dependent Fields in the correct order. This action is more detailed in this Post

    Secondly, as in this link you need to put the OverWrite Attribute in the Elements.xml of the SiteColumn with the lookup, your Elements.xml should look like something like This

    <Field
           ID="{c2f3c9d3-2433-45d5-89a2-4899dc9642f1}"
           Name="FieldName"
           DisplayName="FieldDisplayName"
           Type="Lookup"
           List="Lists/YourList"
           ShowField="FieldToLookupOn"
           Overwrite="TRUE"
           Required="FALSE"
           Group="Custom Site Columns">
      </Field>
    

    And Finally, There is one more work around, it's about to try to BackUp then Restore the site using PowerShell Commands.