Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharepoint lookup field and WebId="

I try to add lookup field in content type. Field has this definition:

<Field ID="{c80e8e3c-7124-4772-a39d-5b69f131d542}"
         Name="Site"
         Group="Tieto Intranet Columns"
         Type="Lookup"
         DisplayName="Site"
         StaticName="Site"
         List="Lists/FavoriteSites"
         ShowField="Title"
         PrependId="TRUE"
         WebId="~sitecollection"
   >

FavoriteSites list, which I want reference by this lookup field, exists on the site collection scope. Deployment goes fine, but when I create list based on content type with this lookup it looks like that lookup field is not connected to FavoriteSites list. I add some data into FavoriteSites and than I a try to add something into second list with lookup field on FavoriteSites. Unfortunately drop down select, which should show me data from FavoriteSites list is empty.

When I create new lookup column to FavoriteSites manually everything is OK.

Do anybody have some idea where can be problem in this lookup definition?

UPDATE:

As Rich recommended me, I set log level on Verbose a find this message:

The WebId=~sitecollection and List=Lists/FavoriteSites attributes specified for field {c80e8e3c-7124-4772-a39d-5b69f131d542} in feature {d86c7005-d31d-43ae-b86b-38f28b81072e} could not be found. Set List={39CEC23E-FB28-47B3-BC36-C21780AD1D94}.

I don't understand it because list FavoriteSites exists. FavoriteSites list and also second list with Site field are deployed by one feature on site collection scope.

I can't specify list in lookup by GUID because I don't know the guid in deployment time.

like image 680
Michal Avatar asked Sep 13 '11 20:09

Michal


2 Answers

What that log message means is that Lists/FavoriteSites does not exist in either the site collection root site or the site where the feature is being activated (if the latter is a subsite).

If Lists/FavoriteSites is being created by a feature, then make sure that it is activated before your Fields feature. Put the ListInstance element right above your Field element if you have to. But the message is clear: the list does not exist at the time that your custom field is being provisioned to the site collection. And that is why it is not working.

To be clear, the list has to exist at the time that the feature is activated, not just when you create a list instance that will use that field.

P.S. I found this by checking the "documentation" for the Microsoft.SharePoint.SPFieldElement.PerformFixUpIfLookUpField method.

like image 136
Rich Bennema Avatar answered Oct 08 '22 22:10

Rich Bennema


Try changing the list field to the ID of the list e.g. List="{4641f5f2-b358-4805-9d7d-e910d2243fb5}"

I would also recommend using SharePointManager to look at the Field definition of your manually created field and to easily find the blooming guids of lists etc.

like image 25
Nat Avatar answered Oct 09 '22 00:10

Nat