Binding a Field to a Term Store - Binding a Field to a Term Store - Community forums - Akumina Community

Community forums

Forum Navigation
Please or Register to create posts and topics.

Binding a Field to a Term Store

Q: How do I bind a list field to a term store?

A: How to add a new term set and then use that term set in a list using the site deployer (or site creator):

First, create a file called "terms.xml" in the Taxonomy folder of your site definition. This file should contain your new term set. For example, I'm creating a term set called MyDeskOnboarding,

<?xml version="1.0" encoding="utf-8" ?>
<termsets>
<termset name="MyDeskOnboarding">
<terms>
<term name="HR" />
<term name="Technology" />
<term name="Financial" />
<term name="Equipment" />
</terms>
</termset>
</termsets>

 

Then you'll need to provision your list. I'm extending an existing content type. If you'd like to use an existing content type, then create a file called ContentTypes.xml in the ContentTypes folder of your site definition. For example, I'm using the AkuminaImportantDates content type and extending it to have a category and person assignment. Note the field called "TaskCategory" binds to the term store using the TermSet attribute:

<?xml version="1.0" encoding="utf-8" ?>
<lists>
<ContentType Name="AkMyDeskTasks" Group="Custom Content Types" Description="" Inherits="TRUE" Version="0" ParentName="AkuminaImportantDates">
<FieldRefs>
<Field Name="Person" DisplayName="Assigned" Type="UserMulti" Required="TRUE" UserSelectionMode="PeopleAndGroups" UserSelectionScope="0" Mult="TRUE" />
<Field Name="TaskCategory" DisplayName="Task Category" Type="TaxonomyFieldType" TermSet="MyDeskOnboarding" Mult="FALSE" />
</FieldRefs>
</ContentType>
</lists>

 

To complete list provisioning, create a file called lists.xml in the ListDefinitions folder of your site definition. In this example, I'm creating a list called MyDeskMyTasks_AK and using the content type defined above:

<?xml version="1.0" encoding="utf-8" ?>
<lists>
<list name="MyDeskMyTasks_AK" noCrawl="TRUE" Enforce="TRUE" contentType="AkMyDeskTasks"></list>
</lists>

 

Wrap it up by populating your list. You can do this in your lists.xml file as well, but I prefer to create an update.xml file in the same folder. Here I'm creating some tasks:

<?xml version="1.0" encoding="utf-8" ?>
<lists>
<list name="MyDeskMyTasks_AK">
<Data>
<Rows>
<Row Update="TRUE">
<Field Name="Title">W-2</Field>
<Field Name="Subtext">Fill out Federal and State W-2 forms.</Field>
<Field Name='StartDate'>2019-09-18T12:00:00Z</Field>
<Field Name='Expires'>2020-12-31T00:00:00Z</Field>
<Field Name="DoNotDisplayThisItem">False</Field>
<Field Name="DetailsLink">{SiteUrl}</Field>
<Field Name="Person">17;#Akumina Inc.</Field>
<Field Name="TaskCategory">Financial;</Field>
</Row>
<Row Update="TRUE">
<Field Name="Title">Direct deposit</Field>
<Field Name="Subtext">Be sure to submit your direct deposit form.</Field>
<Field Name='StartDate'>2019-09-19T12:00:00Z</Field>
<Field Name='Expires'>2020-12-31T00:00:00Z</Field>
<Field Name="DoNotDisplayThisItem">False</Field>
<Field Name="DetailsLink">{SiteUrl}</Field>
<Field Name="Person">17;#Akumina Inc.</Field>
<Field Name="TaskCategory">Financial;</Field>
</Row>
<Row Update="TRUE">
<Field Name="Title">Pick up laptop</Field>
<Field Name="Subtext">Your laptop will be ready by lunch on your first day.</Field>
<Field Name='StartDate'>2019-09-19T12:00:00Z</Field>
<Field Name='Expires'>2020-12-31T00:00:00Z</Field>
<Field Name="DoNotDisplayThisItem">False</Field>
<Field Name="DetailsLink">{SiteUrl}</Field>
<Field Name="Person">17;#Akumina Inc.</Field>
<Field Name="TaskCategory">Equipment;</Field>
</Row>
<Row Update="TRUE">
<Field Name="Title">Office training</Field>
<Field Name="Subtext">On day two you will attend a training session on Microsoft Office.</Field>
<Field Name='StartDate'>2019-09-19T12:00:00Z</Field>
<Field Name='Expires'>2020-12-31T00:00:00Z</Field>
<Field Name="DoNotDisplayThisItem">False</Field>
<Field Name="DetailsLink">{SiteUrl}</Field>
<Field Name="Person">17;#Akumina Inc.</Field>
<Field Name="TaskCategory">Technology;</Field>
</Row>
<Row Update="TRUE">
<Field Name="Title">Lunch with your manager</Field>
<Field Name="Subtext">Your manager has scheduled lunch with you on your third day.</Field>
<Field Name='StartDate'>2019-09-19T12:00:00Z</Field>
<Field Name='Expires'>2020-12-31T00:00:00Z</Field>
<Field Name="DoNotDisplayThisItem">False</Field>
<Field Name="DetailsLink">{SiteUrl}</Field>
<Field Name="Person">17;#Akumina Inc.</Field>
<Field Name="TaskCategory">HR;</Field>
</Row>
</Rows>
</Data>
</list>
</lists>

 

Note that the "TaskCategory" field value must end in a semi-colon.

Be sure to run the addtermsets, lists, and updatelists steps to push your new items.

Hi Brad:

Thanks for sharing this. I have a question related to this; how would I bind a child term to a field? For example I have this term set:

<termset name="Test FAQ Topics">
    <terms>
      <term name="Topic 1">
        <terms>
          <term name="SubCategory 1"/>
          <term name="SubCategory 2"/>
          <term name="SubCategory 3"/>
        </terms>
      </term>
      <term name="Topic 2">
        <terms>
          <term name="SubCategory 1"/>
          <term name="SubCategory 2"/>
          <term name="SubCategory 3"/>
          <terms>
            <term name="SubCategory 3-1"/>
          </terms>
        </terms>
      </term>
    </terms>
  </termset>

I am trying to bind the "Topic 1, SubCategory 1" term to a field. I tried this format where I used the GUID value of the term but I wasn't successful:

<Field Name="SampleMetadata">SubCategory 1|8b28e17a-67fd-4948-9e19-dd1d826f3bb1;</Field>

Any thoughts or suggestions?

Jermaine, just try the name as it may resolve:

 

<Field Name="SampleMetadata">SubCategory 1</Field>

//]]>