Can we create Managed Metadata fields with SPGenesis?

Jul 31, 2012 at 6:12 PM

I have downloaded it and gone through the code. Also, created a few simple text columns and everything is working great.

My only concern right now is whether it can be used to create Taxonomy or Managed Metadata fields. 

Any help would be appreciated.

Thanks.

Coordinator
Aug 3, 2012 at 11:11 PM

Of course you can :)

Managed metadata field are a bit tricky to setup because you need to get hold of the term store properties to use. This can only be done in runtime when provisioning. Something like this should work:

    [SPGENField(
        ID = "{18647551-5501-FD99-A140-4124A47FAA91}",
        CustomType = "TaxonomyFieldType",
        DisplayName = "MyTaxonomyField")]
    public class MyTaxonomyField : SPGENField<MyTaxonomyField, TaxonomyField, object>
    {
        protected override void OnProvisionFinalized(TaxonomyField field, SPFieldCollection fieldCollection, bool isParentList, bool updatedOnly)
        {
            TaxonomySession session = new TaxonomySession(fieldCollection.Web.Site);

            TermStore termstore = session.TermStores["(TermStoreName)"];
            Group group = termstore.Groups["(TermGroupName)"];
            TermSet termset = group.TermSets["(TermSetName)"];

            field.SspId = termstore.Id;
            field.TermSetId = termset.Id;
            field.AllowMultipleValues = false;

            field.Update(true);
        }
    }

Aug 4, 2012 at 4:00 PM

Thank you very much!