0

My requirement is to create a Custom List using the Feature (SPFx solution). I have created a custom list using the SPFx feature, I have created a different type of field. But now I want to create a Lookup column using this feature, But I'm not able to create a Lookup column.

I have tried, List="Lists/City" and also tried "List="City" but it is not working. Other fields are created but the Lookup column is not created. If I provided a list GUID then also I'm not able to create a Lookup column.

following is my xml schema to create a Lookup column.

     <Field ID="{95d89725-eb97-428b-bc79-ee02ca8b724c}"
         Name="City"
         SourceID="http://schemas.microsoft.com/sharepoint/v3"
         StaticName="City"
         Type="Lookup"
         DisplayName="City"
         List="City"
         FieldRef="ID"
         ShowField="Title"
    /> 

Tell me how I can create the Lookup column using the SPFx feature with XML schema.

1 Answer 1

1

I was able to create a lookup column using this CAML:

<Field 
    ID="{3578a673-d4db-4f2e-b721-2c68eb994588}" 
    Name="SpfxCity" 
    DisplayName="City" 
    Type="Lookup" 
    List="Lists/City" 
    ShowField="Title"
    Group="SPFx Columns" />

Here's the complete elements.xml file that I used.

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

    <Field 
        ID="{3578a673-d4db-4f2e-b721-2c68eb994588}" 
        Name="SpfxCity" 
        DisplayName="City" 
        Type="Lookup" 
        List="Lists/City" 
        ShowField="Title"
        Group="SPFx Columns" />

    <ContentType ID="0x01008A91C228836E480F987C78C60518A422"
            Name="SPFx Content Type"
            Group="SPFx Content Types"
            Description="Sample content types from web part solution">
        <FieldRefs>
            <FieldRef ID="{3578a673-d4db-4f2e-b721-2c68eb994588}" />
        </FieldRefs>
    </ContentType>

    <ListInstance
            CustomSchema="schema.xml"
            FeatureId="00bfea71-de22-43b2-a848-c05709900100"
            Title="SPFx List"
            Description="SPFx List"
            TemplateType="100"
            Url="Lists/SPFxList">
    </ListInstance>

</Elements>

Here's the complete schema.xml that I used.

<List xmlns:ows="Microsoft SharePoint" Title="SPFx List" EnableContentTypes="TRUE" FolderCreation="FALSE" Direction="$Resources:Direction;" Url="Lists/SPFxList" BaseType="0" xmlns="http://schemas.microsoft.com/sharepoint/">
  <MetaData>
    <ContentTypes>
      <ContentTypeRef ID="0x01008A91C228836E480F987C78C60518A422" />
    </ContentTypes>
    <Fields></Fields>
    <Views>
      <View BaseViewID="1" Type="HTML" WebPartZoneID="Main" DisplayName="$Resources:core,objectiv_schema_mwsidcamlidC24;" DefaultView="TRUE" MobileView="TRUE" MobileDefaultView="TRUE" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/generic.png" Url="AllItems.aspx">
        <XslLink Default="TRUE">main.xsl</XslLink>
        <JSLink>clienttemplates.js</JSLink>
        <RowLimit Paged="TRUE">30</RowLimit>
        <Toolbar Type="Standard" />
        <ViewFields>
          <FieldRef Name="LinkTitle"></FieldRef>
          <FieldRef Name="SpfxCity"></FieldRef>
        </ViewFields>
        <Query>
          <OrderBy>
            <FieldRef Name="ID" />
          </OrderBy>
        </Query>
      </View>
    </Views>
    <Forms>
      <Form Type="DisplayForm" Url="DispForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
      <Form Type="EditForm" Url="EditForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
      <Form Type="NewForm" Url="NewForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
    </Forms>
  </MetaData>
</List>

I tried to follow the example shown in this tutorial as much as possible: Provision SharePoint assets from your SharePoint client-side web part. Please note that there appears to be a step missing in this tutorial. You need to ensure that the skipFeatureDeployment property in package-solution.json is set to false.

I hope this helps.

2
  • Thank you @Rob Windsor. Yes. this way created. I have not created List Columns and Content Type. I was trying to create a List Column. But this way also worked for me Apr 4, 2022 at 4:06
  • I have 1 problem here, I'm creating a Lookup list in the Same Feature. I'm able to create a Lookup Column but I'm not able to see it in the List. It was also added to the Content-Type but not shown in the List. Can you @Rob Windsor tell me why? Apr 6, 2022 at 3:26

Your Answer

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

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