1

Here I have created the custom managed metadata column in visual studio.as like below.

 <Field
           Type="TaxonomyFieldTypeMulti"
           DisplayName="Document Type"
           StaticName="DocumentType"
           Name="DocumentType"
           Group="ManagedMetaData"
           ShowField="Term1033"
           Description="Managed Metadata for the Document Type."
           Required="FALSE"
           EnforceUniqueValues="FALSE"
           ID="{8B2F26F1-9A2B-41E5-BFC3-63D9CB4A7703}"
           DisplaceOnUpgrade="TRUE"
           Overwrite="TRUE"
           Mult="FALSE">
    <Customization>
      <ArrayOfProperty>
        <Property>
          <Name>TextField</Name>
          <Value xmlns:q6="http://www.w3.org/2001/XMLSchema"
                           p4:type="q6:string"
                           xmlns:p4="http://www.w3.org/2001/XMLSchema-instance">{28226668-3DDE-46F2-875B-CA7A873A468E}</Value>
        </Property>
      </ArrayOfProperty>
    </Customization>
  </Field>

which I am including in the Content Type and binding this content type to custom list(Here i am creating a calendar list).

and there is some c# code which I am Adding to the event receiver. that is as below.

 string groupName = "groupName";
        Dictionary<string, string> termDictionary = new Dictionary<string, string> { { "Document Type", "{8B2F26F1-9A2B-41E5-BFC3-63D9CB4A7703}" } };
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWeb currentSite = null;
            if (properties.Feature.Parent is SPWeb)
            {
                currentSite = (SPWeb)properties.Feature.Parent;
            }
            else if (properties.Feature.Parent is SPSite)
            {
                currentSite = ((SPSite)properties.Feature.Parent).RootWeb;
            }
            if (currentSite != null)
            {
                CreateGroupTermSet(currentSite);
                foreach (var termItem in termDictionary)
                {
                    AssociateMetadata(currentSite, new Guid(termItem.Value), termItem.Key);
                }
            }
            currentSite.Close();
        }

        private void CreateGroupTermSet(SPWeb currentSite)
        {
            TaxonomySession ts = new TaxonomySession(currentSite.Site);
            TermStore termStore = ts.TermStores[0];
            if (!termStore.Groups.Any(g => g.Name == groupName))
            {
                Group group = termStore.CreateGroup(groupName);
                foreach (var termName in termDictionary)
                {
                    if (!group.TermSets.Any(g => g.Name == termName.Key))
                    {
                        TermSet termSetDepartment = group.CreateTermSet(termName.Key);
                        termSetDepartment.IsOpenForTermCreation = true;
                    }
                }
            }
            termStore.CommitAll();
        }

        private void AssociateMetadata(SPWeb currentSite, Guid fieldId, string termSetName)
        {
            if (currentSite.Site.RootWeb.Fields.Contains(fieldId))
            {
                TaxonomySession session = new TaxonomySession(currentSite.Site);

                TermStoreCollection termStores = session.TermStores;
                if (session.TermStores.Count != 0)
                {
                    var termStore = session.TermStores["Managed Metadata Service"];

                    var termGroup = termStore.Groups[groupName];
                    var termSet = termGroup.TermSets[termSetName];

                    TaxonomyField field = currentSite.Site.RootWeb.Fields[fieldId] as TaxonomyField;

                    field.SspId = termSet.TermStore.Id;
                    field.TermSetId = termSet.Id;
                    field.TargetTemplate = string.Empty;
                    field.AnchorId = Guid.Empty;
                    field.CreateValuesInEditForm = true;
                    field.Open = true;
                    field.Update();
                }
            }
        }

after doing all this stuff i am simply deploying this solution on site collection where i am trying to add the term inside the list but that filed is disabled which is not allowing me to enter term.that looks a like as below snap. enter image description here

but here if i am creating a any other list manualy in site collection and assigning the same content type to it then there i can add this data.you can see that in below snap. enter image description here so here i am not able to fugure it out like what is the wrong thing i am doing?

  • did you checked the column property in list? Is it coming from content type or not? – ThinkB4Code Sep 13 '17 at 10:32
1

Resolved the Issue by Adding the note filed to that metadata column as like below and Adding the same Note field column to the List.

<Field
           Type="TaxonomyFieldTypeMulti"
           DisplayName="Document Type"
           StaticName="DocumentType"
           Name="DocumentType"
           Group="ManagedMetaData"
           ShowField="Term1033"
           Description="Managed Metadata for the Document Type."
           Required="FALSE"
           EnforceUniqueValues="FALSE"
           ID="{8B2F26F1-9A2B-41E5-BFC3-63D9CB4A7703}"
           DisplaceOnUpgrade="TRUE"
           Overwrite="TRUE"
           Mult="FALSE">
    <Customization>
      <ArrayOfProperty>
        <Property>
          <Name>TextField</Name>
          <Value xmlns:q6="http://www.w3.org/2001/XMLSchema"
                           p4:type="q6:string"
                           xmlns:p4="http://www.w3.org/2001/XMLSchema-instance">{28226668-3DDE-46F2-875B-CA7A873A468E}</Value>
        </Property>
      </ArrayOfProperty>
    </Customization>
  </Field>
 <Field Type="Note"
           DisplayName="DocumentType_0"
           StaticName="DocumentTypeTaxHTField0"
           Name="DocumentTypeTaxHTField0"
           ID="{28226668-3DDE-46F2-875B-CA7A873A468E}"
           ShowInViewForms="FALSE"
           Required="FALSE"
           Hidden="TRUE"
           CanToggleHidden="TRUE"
           Group="ManagedMetaData"
           RowOrdinal="0"
    />
| improve this answer | |
0

You should check te sequence how the list is created. First deploy site columns and contenttypes to your site using a different feature with an event receiver to set the tax field. In different feature add the list to your site.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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