Sunday, September 9, 2012

How To Create Solution Package To Deploy Lists With Lookup Columns

To save the time and work pressure,Some of the developers end up deploying lists by 'Save As Template' method.
My request to all those developers is not to go by that way(specially for new learners). Just take the advantage of ,What feature MS Visual Studio 2010 for SharePoint provides.
 Because there are several disadvantage of this ('Save as Template') method. and When it comes for the lists with Parent-Child relationship which includes lookup column it's terrible.
Not only for this post,think of deployment perspective while finalizing any approach for development.
To Develop solution package for Lists With Lookup Columns
A)Create Content Type and Site Columns for Parent List 
1)Navigate to any source SharePoint site.
Site action -->Site Settings-->Site Columns Create site column 'Parent Column' with Single line of Text

Now add this site column to Parent Content Type,
to do so,create new Content Type which inherits from List Content Type and add parent column

2)Create Custom List ParentList  and Enable management of Content Type of this List(List Settings 
-->Allow management Of Content Type
Add from existing  Site Content Type and Select Parent Lookup Content Type
and delete the existing Item Content Type

B)Create Content Type and Site Columns for Child List
 Site action -->Site Settings-->Site Columns Create site column 'Foreign Column' with Lookup Type as described in below image
  Now add this site column to Child Content Type  and Associate this content type with Child List in the similar way , as that of Parent List(As described above in Section A )

C)Get the wsp file of the site and Import to Visual Studio
1)Browse to _Layouts/savetmpl.aspx with include contents check box checked and save it to the local disk(this link is not visible for publishing sites in site settings)
2)Visual Studio 2010-->run as admin-->New Project-->SharePoint-->Import Solution Package.
Select deploy as Farm solution and select the wsp saved in above in Step  C 1.
Press Shift on Keyboard,select first and last row and uncheck all the files shown in grid
Now you have to be very careful.Make sure that following items are selected before clicking on next
1)Parent Column, Foreign Column(Child Column) site columns
2)Parent Content Type and  Child Content Types
3)Parent List Instance and  Child List Instance
4)ListParentList_Pages and ListChildList_Pages

On clicking Finish ,If you get Popup for  dependencies,Click on 'No'  and Solution should appear like below

Please add to the comments If you get any deployment errors.while doing this activity. I renamed the Child List before Importing.so I got the deployment errors for List not found .Then I ran replace all for new list name and Its working now :)

If during deployment few more columns and Content type needs to be deployed , get  the schema  through powershell add to this solution.

Download Source

No comments: