Wednesday, August 29, 2012

lookups in SharePoint 2010

My Elements.xml now looks like this:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
   <Field ID="{2962C4A9-C298-4393-9234-EAF9CCCD8CA0}" Name="LoginName"
         Type="User" DisplayName="Login Name" StaticName="LoginName"
         Required="TRUE" UserSelectionMode="PeopleOnly" ShowField="Name" />
   <Field ID="{0C5A1104-AD4A-4048-AB08-FAF62814D54B}" Name="LoginIsActive"
         Type="Boolean" DisplayName="Active?" StaticName="LoginIsActive"
         Required="TRUE">
      <Default>1</Default>
   </Field>
   <Field ID="{85ECCAB3-F5A4-4CA9-86E0-BDBC191D64EE}" Name="TypeOfLocation"
         Type="Text" DisplayName="Type Of Location" StaticName="Type Of Location"
         Group="List Content Types" />
   <Field ID="{85EDDAB3-F5A4-4CA9-86E0-BDBC191D64DD}"
            Name="LocationType"
            Type="Lookup"
            DisplayName="LocationType"
            StaticName="Location Type"
            List="Lists/SharePoint.FSC.AOPC-ListInstance1"
            ShowField="TypeOfLocation"
            Required="TRUE"
            Description="This is a list of ways to define the location boundaries for a credit
                  card."
            Group="List Content Types"
            />
   <ContentType ID="0x01004fd59ec931f9478c990051d6fe455f36" Name="CardHolder"
         Group="List Content Types" Description="CardHolder Columns"
         Inherits="FALSE" Version="0">
      <FieldRefs>
         <FieldRef ID="{2962C4A9-C298-4393-9234-EAF9CCCD8CA0}"
               Name="LoginName" />
         <FieldRef ID="{0C5A1104-AD4A-4048-AB08-FAF62814D54B}">
               Name="LoginIsActive" />
      </FieldRefs>
   </ContentType>
   <ContentType ID="0x01004fd59ec931f9478c990051d6fe455f37" Name="LocationTypes"
         Group="List Content Types" Description="Location Types Columns"
         Inherits="FALSE" Version="0">
      <FieldRefs>
         <FieldRef ID="{85ECCAB3-F5A4-4CA9-86E0-BDBC191D64EE}"
               Name="TypeOfLocation" />
      </FieldRefs>
   </ContentType>
   <ContentType ID="0x01004fd59ec931f9478c990051d6fe455f44"
         Name="CardHolderCard" Group="List Content Types"
         Description="CardHolder Card Columns" Inherits="FALSE" Version="0">
      <FieldRefs>
         <FieldRef ID="{85EDDAB3-F5A4-4CA9-86E0-BDBC191D64DD}"
               Name="LocationType" />
      </FieldRefs>
   </ContentType>
</Elements>

 
 

The List value in my Lookup field references the the URL value in an application List Instance...

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
   <ListInstance Title="Location Types"
                        OnQuickLaunch="TRUE"
                        TemplateType="10000"
                        Url="Lists/SharePoint.FSC.AOPC-ListInstance1"
                        Description="My List Instance">
      <Data>
         <Rows>
            <Row>
               <Field Name="TypeOfLocation">Area</Field>
            </Row>
            <Row>
               <Field Name="TypeOfLocation">MSN</Field>
            </Row>
            <Row>
               <Field Name="TypeOfLocation">Office#</Field>
            </Row>
            <Row>
               <Field Name="TypeOfLocation">VISN</Field>
            </Row>
         </Rows>
      </Data>
   </ListInstance>
</Elements>

 
 

Oyekan Olufemi gave me a blob of copy that explained this vital wireup which read: Optional Text. Used to identify the list that is the target of a lookup field (Type="Lookup"). If the target list already exists, the value of the List attribute should be the string representation of the GUID (including braces) that identifies the target list. If the target is the same list as the one that the field belongs to, you can specify "Self". If the target list does not yet exist, the value of the List attribute can be a web-relative URL such as "Lists/My List" but only if the target list is created in the same feature as the one that creates the lookup field. In this case, the value of the List attribute on the Field element must be identical to the value of the Url attribute on the ListInstance element that creates the target list.

 
 

Mistakes I've made in trying to set the List value included using http://fscee42471-2/AOPCPortal/Lists/SharePoint.FSC.AOPC-ListInstance1/ as the URL where such is a deployment off the List Instance. From http://fscee42471-2/AOPCPortal/Lists/SharePoint.FSC.AOPC-ListInstance1/ if I go to: List Tools > List > List Settings I end up at http://fscee42471-2/AOPCPortal/_layouts/listedit.aspx?List=%7BE4D93855%2D549B%2D4AB2%2DAB43%2D6A33BC0E636F%7D and I made the mistake of using {E4D93855-549B-4AB2-AB43-6A33BC0E636F} (cleaned up from %7BE4D93855%2D549B%2D4AB2%2DAB43%2D6A33BC0E636F%7D) as the list value also and this too did not work.

 
 

If I use the CardHolderCard ContentType in a custom list. I will end up with a dropdown that has no default value but which may be changed to allow for selections for:

  1. Area
  2. MSN
  3. Office#
  4. VISN

 
 

Outside of Visual Studio, at a SharePoint deployment, I needed to follow thirteen these steps (which I found at http://msdn.microsoft.com/en-us/library/ff630940.aspx) to create a custom list and associate the CardHolderCard ContentType to it:

  1. Start Internet Explorer and browse to the Web site where you have created the new content type.
  2. In the upper-left corner of the page, click Site Actions and then click More Options.
  3. Click List in the Filter By menu in the Create dialog screen.
  4. Select Custom List.
  5. Type New Announcements as the name and then click Create.
  6. Click List Settings in the SharePoint 2010 ribbon and then under General Settings, click Advanced settings.
  7. Click Yes for Allow management of content types and then click OK.
  8. Under the Content Types section, click the Item content type.
  9. Under Settings, click Delete this content type.
  10. If prompted for confirmation, select OK.
  11. Under the Content Types section, click Add from existing site content types.
  12. From the available site content types list, click New Announcements and then click Add.
  13. Click OK. You should now see the New Announcements content type associated with the New Announcements list.

 
 

After these steps, one may go to: List Tools > List > Modify View > Modify View ...to unhide the lookup column and hide the default columns. (While experimenting I realized that: List Tools > List > Edit List ...opened SharePoint designer.)

 
 

I realized that I could make custom lists in a SharePoint deployment and still redeploy the content in Visual Studio without sabotaging my environment-specific list. This is because only a package is deployed and not the whole of the SharePoint site.

 
 

At Site Actions > Site Settings > Site columns > Create ...one may manually create a lookup column

No comments:

Post a Comment