SharePoint Config

Ari Bakker's thoughts on customising and configuring SharePoint

Provisioning SharePoint 2010 Managed Metadata fields

with 54 comments

The first part of this two part series discussed some of the problems with provisioning SharePoint 2010 managed metadata fields. This post will cover a robust method of deploying SharePoint 2010 managed metadata columns in a way that avoids common errors and enables the columns to automatically show up in the search refinement panel.

To recap on the previous post we are aiming to avoid the following problems when creating SharePoint 2010 taxonomy fields through features:

  1. If you create a list definition that uses this site column you get the error: Failed to get value of the “{0}” column from the “Managed Metadata” field type control. See details in log. Exception message: Invalid field name. {00000000-0000-0000-0000-000000000000}.
  2. The managed metadata column does not appear in the search refinement panel as per columns created through the UI.
  3. If the managed metadata features are not activated in the site the field will not work (and no obvious errors will be displayed).

We found the first problem was due to a missing note field when creating a list definition that used the site column. The second problem was due to the missing TaxCatchAll and TaxCatchAllLabel columns and missing event receivers on the list definition. The last issue can be easily avoided by adding a feature dependency to ensure the required feature is activated before we deploy our custom site column. With this information we can use the following steps to deploy managed metadata fields that avoid these issues. I’ve also created an example project that I’ve included at the end of the article if you want to see this working for yourself.

Create a managed metadata field

  1. Provision a managed metadata field using type TaxonomyFieldType (or TaxonomyFieldTypeMulti to allow multiple values)
  2. Configure the managed metadata column to reference an existing term set
  3. Provision a hidden field of type Note
  4. Configure the managed metadata column to use the hidden Note field
  5. Ensure that the TaxonomyFieldAdded feature is activated on the site collection

Create a list definition that uses a managed metadata field

  1. Create a content type that uses the managed metadata fields and the TaxCatchAll columns
  2. Create a list definition that uses the content type and includes all metadata and TaxCatchAll columns
  3. Attach the TaxonomyItemSynchronousAddedEventReceiver and TaxonomyItemUpdatingEventReceiver event receivers to the list definition
  4. Create a list instance to provision instances of the list definition

Create a managed metadata field

1. Provision a managed metadata field

The first step is to create a site column using the Field element with a Type of either TaxonomyFieldType (allowing a single selection) or Type TaxonomyFieldTypeMulti (allowing multiple selections if you also set Mult=”True”).

<Field ID="{F88D530B-705F-488A-9069-FAF5C79B61F7}"
    Type="TaxonomyFieldType"
    DisplayName="Regional Office"
    ShowField="Term1033"
    EnforceUniqueValues="FALSE"
    Group="Custom Columns"
    StaticName="RegionalOffice"
    Name="RegionalOffice">
</Field>

Configure the managed metadata column to reference an existing term set

To link the field to a term set so users can select terms you can either add a <Customization/> section to the field and hardcode the various Id’s that define a term set (required if you are using a sandboxed solution), or configure these in code. I’m taking the code approach here as it is the only way to ensure the field will work across multiple environments.

I’ve based the code on Wictor’s excellent example with a couple of minor updates. Instead of hardcoding the name of the term store I’m getting the default keyword store associated with the site (this means we do not have to hardcode the name of the managed metadata service but you should check this works in all your environments). I’ve also added in some additional error handling so we get informative messages if the metadata service and/or term set does not exist.

public class RegionalOfficeEventReceiver : SPFeatureReceiver
{
    public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        SPSite site = properties.Feature.Parent as SPSite;
        ConnectTaxonomyField(site,
            new Guid("{F88D530B-705F-488A-9069-FAF5C79B61F7}"),
            "Global",
            "Office Locations");
    }

 

    public static void ConnectTaxonomyField(SPSite site, Guid fieldId, string termGroup, string termSetName)
    {
        if (site.RootWeb.Fields.Contains(fieldId))
        {
            TaxonomySession session = new TaxonomySession(site);

 

            if (session.DefaultKeywordsTermStore != null)
            {
                // get the default metadata service application
                var termStore = session.DefaultKeywordsTermStore;
                var group = termStore.Groups.GetByName(termGroup);
                var termSet = group.TermSets.GetByName(termSetName);
                TaxonomyField field = site.RootWeb.Fields[fieldId] as TaxonomyField;
                // connect the field to the specified term
                field.SspId = termSet.TermStore.Id;
                field.TermSetId = termSet.Id;
                field.TargetTemplate = string.Empty;
                field.AnchorId = Guid.Empty;
                field.Update();
            }
            else
            {
                throw new TermStoreNotFoundException(string.Format("DefaultKeywordsTermStore not found in site {0}", site.Url));
            }
        }
        else
        {
            throw new ArgumentException(string.Format("Field {0} not found in site {1}", fieldId, site.Url), "fieldId");
        }
    }
}

 

[Serializable]
public class TermStoreNotFoundException : Exception
{
    public TermStoreNotFoundException() { }
    public TermStoreNotFoundException(string message) : base(message) { }
    public TermStoreNotFoundException(string message, Exception inner) : base(message, inner) { }
    protected TermStoreNotFoundException(
      System.Runtime.Serialization.SerializationInfo info,
      System.Runtime.Serialization.StreamingContext context)
        : base(info, context) { }
}

 

public static class TaxonomyExtensions
{
    public static Group GetByName(this GroupCollection groupCollection, string name)
    {
        if (String.IsNullOrEmpty(name))
        {
            throw new ArgumentException("Taxonomy group name cannot be empty", "name");
        }
        foreach (var group in groupCollection)
        {
            if (group.Name == name)
            {
                return group;
            }
        }
        throw new ArgumentOutOfRangeException("name", name, "Could not find the taxonomy group");
    }

 

    public static TermSet GetByName(this TermSetCollection termSets, string name)
    {
        if (String.IsNullOrEmpty(name))
        {
            throw new ArgumentException("Term set name cannot be empty", "name");
        }
        foreach (var termSet in termSets)
        {
            if (termSet.Name == name)
            {
                return termSet;
            }
        }
        throw new ArgumentOutOfRangeException("name", name, "Could not find the term set");
    }
}

 

Note that if we are only creating a site column (or even a content type) this should work without completing the following steps. When we add either the site column or content type to a list the managed metadata field works and shows up in the search refinement panel (at least it did in my testing). This is due to the fact that SharePoint automatically wires some extra bits (shown below) when the field is added. At least in my testing when we create a list definition this isn’t all wired up correctly and the following steps were required.

Provision a hidden field of type Note

This and the following step is often missed out in other articles but cause problems if you try to create custom list definitions that include the managed metadata column. The specific error message you get is:

Error – Failed to get value of the “{0}” column from the “Managed Metadata” field type control. See details in log. Exception message: Invalid field name. {00000000-0000-0000-0000-000000000000}

sp2010-managed-metadata-field-error

The problem stems from the fact that SharePoint is looking for an associated note (i.e. text) field that is required for the metadata column to work. The first taxonomy field we created actually only stores a lookup value to a list within the current site collection and it is the note field that actually stores the names and Id’s of each selected term. So to create this note field we can add a field similar to the following:

<Field Type="Note"
    DisplayName="Regional Office_0"
    StaticName="RegionalOfficeTaxHTField0"
    Name="RegionalOfficeTaxHTField0"
    ID="{9EDAB26E-CC44-4027-AB05-CB44EA3A6F72}"
    ShowInViewForms="FALSE"
    Required="FALSE"
    Hidden="TRUE"
    CanToggleHidden="TRUE"
    RowOrdinal="0" />

Note: SharePoint uses the suffix _0 appended to the display name of the field and TaxHTField0 after the static name so I’m following those conventions.

Configure the managed metadata column to use the hidden Note field

To link the two together we can update the field we created in step one to include a customization section that points to the note field as shown below:

<Field ID="{F88D530B-705F-488A-9069-FAF5C79B61F7}"
    Type="TaxonomyFieldType"
    DisplayName="Regional Office"
    ShowField="Term1033"
    EnforceUniqueValues="FALSE"
    Group="Custom Columns"
    StaticName="RegionalOffice"
    Name="RegionalOffice">
    <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">{9EDAB26E-CC44-4027-AB05-CB44EA3A6F72}</Value>
            </Property>
        </ArrayOfProperty>
    </Customization>
</Field>

Note the value within the TextField property is the ID of the note field we created above.

Ensure that the TaxonomyFieldAdded feature is activated on the site collection

This is another step that isn’t always mentioned but if this feature is not present then you are presented with a greyed out metadata selection when adding or editing items (note this also happens if the field is not connected to a term set). You won’t get any obvious error messages and the feature is hidden so you won’t see it in the site features list either.

sp2010-managed-metadata-field-disabled

The TaxonomyFieldAdded feature is not activated on sites created using the blank site template, or sites created using custom site definitions so a good idea is to include a feature activation dependency that ensures this is activated before we attempt to provision our field. This is easy to do using the Visual Studio 2010 feature editor – just expand the Feature Activation Dependencies section at the bottom and add the following information:

Title: TaxonomyFieldAdded

Feature ID: 73ef14b1-13a9-416b-a9b5-ececa2b0604c

Description: Register taxonomy site wide field added event receiver

Assuming the feature that contains the site columns is site scoped this feature will activate automatically if it isn’t already activated.

vs2010-feature-activation-dependency

At this point we have a robust way of deploying a standalone site column which is useful in certain situations but in many situations we need to provision content types, list definitions and list instances which is when things get tricky…

Create a list definition that uses a managed metadata field

As explained in the previous post Issues provisioning SharePoint 2010 Managed Metadata fields – to ensure the metadata field automatically appears in the search refinement panel as it does for all other managed metadata fields we need to add the TaxCatchAll columns to our list definition and wire up two taxonomy event receivers.

Create a content type that uses the managed metadata field

I find the easiest way to ensure all the columns are added to the list definition is to add them to a content type first. This content type should contain the managed metadata/taxonomy field, the note field and the TaxCatchAll and TaxCatchAllLabel fields as shown below.

<!-- Parent ContentType: Document (0x0101) -->
<ContentType ID="0x0101006d47bceb88064a04a63716fe4609647a"
    Name="Regional Document"
    Group="Custom Content Types"
    Description="My Content Type"
    Inherits="TRUE"
    Version="0">
    <FieldRefs>
        <FieldRef ID="{F88D530B-705F-488A-9069-FAF5C79B61F7}" Name="RegionalOffice"/>
        <FieldRef ID="{9EDAB26E-CC44-4027-AB05-CB44EA3A6F72}" Name="RegionalOfficeTaxHTField0"/>
        <FieldRef ID="{f3b0adf9-c1a2-4b02-920d-943fba4b3611}" Name="TaxCatchAll"/>
        <FieldRef ID="{8f6b6dd8-9357-4019-8172-966fcd502ed2}" Name="TaxCatchAllLabel"/>
    </FieldRefs>
</ContentType>

Create a list definition that uses the content type and includes all metadata and TaxCatchAll columns

We can do this first step using the Visual Studio 2010 tools to create a list definition from the content type we created earlier. As we added the TaxCatchAll columns to our content type these will automatically be added to our list definition.

Sidenote: you want to remove the /Lists/ prefix from the URL when creating document libraries to avoid breaking the default column values feature. You will also want to add in the file dialog view as it goes missing when using the Visual Studio 2010 tools.

Attach the TaxonomyItemSynchronousAddedEventReceiver and TaxonomyItemUpdatingEventReceiver event receivers to the list definition

If we inspect a list that contains a managed metadata field created through the UI it shows two event receivers. These are the TaxonomyItemSynchronousAddedEventReceiver for the ItemAdding event and the TaxonomyItemUpdatingEventReceiver for the ItemUpdating event. To add these to our custom list definition we use an element file similar to the one below (note the ListTemplateId should match the Type attribute of our list definition).

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Receivers ListTemplateId="10700">
      <Receiver>
        <Name>TaxonomyItemSynchronousAddedEventReceiver</Name>
        <Type>ItemAdding</Type>
        <Assembly>Microsoft.SharePoint.Taxonomy, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
        <Class>Microsoft.SharePoint.Taxonomy.TaxonomyItemEventReceiver</Class>
        <SequenceNumber>10000</SequenceNumber>
      </Receiver>
      <Receiver>
        <Name>TaxonomyItemUpdatingEventReceiver</Name>
        <Type>ItemUpdating</Type>
        <Assembly>Microsoft.SharePoint.Taxonomy, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
        <Class>Microsoft.SharePoint.Taxonomy.TaxonomyItemEventReceiver</Class>
        <SequenceNumber>10000</SequenceNumber>
      </Receiver>
  </Receivers>
</Elements>

Create a list instance to provision instances of the list definition

As a final step we can optionally create a list instance so that when we deploy our solution lists are created automatically. This should be done as a separate web scoped feature. All going well we will now have a list that contains a correctly functioning managed metadata field which automatically gets extracted during search processing and displayed in the search refinement panel as shown below.

sp2010-managed-metadata-term-setExample Project

I’ve included the code above in a Visual Studio 2010 project to deploy a managed metadata field as I always find examples work best for this type of thing.

To run the project you will need a machine with Visual Studio 2010, SharePoint Server 2010 and and managed metadata service with a Group named ‘Global’ and a Term Set named ‘Office Locations’ (or you can wire this up to a term set of you choice by changing the code in the feature receiver).

 

I’m sure there are other rough edges that I haven’t covered yet so let me know if you have come across any other odd behaviour when provisioning managed metadata site columns in the comments below.

Post to Twitter Post to Delicious Post to Digg Post to Reddit Post to StumbleUpon

Written by Ari Bakker

March 8th, 2011 at 11:16 am

54 Responses to 'Provisioning SharePoint 2010 Managed Metadata fields'

Subscribe to comments with RSS or TrackBack to 'Provisioning SharePoint 2010 Managed Metadata fields'.

  1. Hi Ari
    Just been having a conversation with Anders Rask and he says you should include DisplayOnUpgrade which is set declaratively in field manifest and also set TextField in feature receiver as he has had experience of the field being corrupted on upgrade.

    Regards

    Nigel

    Nigel Price

    8 Mar 11 at 12:42 pm

  2. Good article! Will definetely check out the TaxCatchAll and TaxCatchAllLabel fields, as i dont add those at the moment.

    As Nigel say, use DisplaceOnUpgrade=”true” on all taxonomy fields. This tells SharePoint that if the field definition already exists we want to overwrite it with the new declarative xml (eg. the issue i mentioned on your Part 1 blog post, where i noticed multiple orphaned hidden notes fields).

    Setting TextField in the feature receiver means you got everything in one place, but since you know your ID already i guess you could opt for adding it declaratively as well (as you do)

    Anders Rask

    9 Mar 11 at 8:54 am

  3. @Nigel, @Anders I’ve done some tests and if you use the method above to set the TextField as you provision the field these will upgrade without any problems. As you mention if you do not include the TextField during initial provisioning then you run into all sorts of problems (errors and corruption on upgrade in some case). In this case you would need to use the DisplaceOnUpgrade=”true” to upgrade them to use the correct TextField but if you use the method above this isn’t necessary.

    Ari Bakker

    13 Mar 11 at 1:00 pm

  4. I have a question, I published an infopath form published as an administrator approved form, the i activate de form on a collection site then i added my form on a document library but how do i need to do that use those fields as managed properties beacuse i can’t see de ows_fields

    Victor Melo

    31 Mar 11 at 4:41 am

  5. Hi,

    As an aside , I had gone live with the metadata fieds and needed to find a solution, especially as my content types were part of a content type hub..

    To workaround I actually added the fields in a feature upgrade , using AddContentTypeField node as discussed in Chris O Brien’s article ,http://www.sharepointnutsandbolts.com/2010/06/feature-upgrade-part-1-fundamentals.html

    and It worked just fine , other methods ie adding programatically didnt work for me, but this does..

    Stuart Evans

    7 Apr 11 at 12:56 pm

  6. Absolutely brilliant article! The hidden note field requirement is a bit of a gotcha, thanks for sharing 🙂

    Henry Chong

    30 Apr 11 at 9:41 am

  7. […] and a fantastic blog post about exactly what you need to do, which you can find in its entirety here – definitely worth a […]

  8. […] level of extra complexity for us as developers. These issues are already discussed at length here: http://www.sharepointconfig.com/2011/03/the-complete-guide-to-provisioning-sharepoint-2010-managed-m… so I won’t get into the details of the issues but only provide a quick guide for provisioning […]

  9. Hi, have you come across when the feature is deactivated, the notes fields still remain in sharepoint, this makes feature redepoyment/reactivation difficult? i have included the line below in feature deactivation but still cannot get rid of it…

    currentWeb.Fields(“Note Field DisplayName_0”).Delete()

    Any idea?

    BTW, awesome article.

    Ben L

    23 May 11 at 9:56 am

  10. Hi Ari,

    Thank you for the great guide. I followed your post and successfully created a managed metadata site column. I was able to use the site column in a list that I created and everything went smoothly; however, when I went to deactivate, retract, and remove the feature and the solution, I expected to see the site column disappear from my site collection. The site column is still stubbornly there!

    My question: Do we need to write additonal code in the FeatureUninstalling method to have the site column completely removed? (BTW, I had also created two more ‘generic’ site columns -single line text and choice – within the same feature and they were removed properly upon feature deactivation). Looking forward to hearing form you. Thank you again!

    MSS

    24 Jun 11 at 11:02 pm

  11. […] SharePoint Config: Provisioning SharePoint 2010 Managed Metadata fields […]

  12. Just wish to say that your article has helped a great deal for me. The sample project file really helps me as well.

    Leo

    20 Jul 11 at 2:33 am

  13. Hi. Great Article. I’ve following it to a “T” and it worked for a while. After a few deployments and retractions, etc I’m getting the original error again, but instead of a GUID of {00000…}, it’s displaying the GUID for the NoteField that I defined. Looking at this field using SharePoint Manager, I see that there are three fields with appended “_x”, like this “MyField_0” and “MyField_1.” Someone commented earlier that these could not be deleted, and I am finding that is true as well. I could really use some help. Thank you!

    JakeJ

    28 Jul 11 at 4:02 pm

  14. @Ben L and @MSS – if you make updates to a column (content type or list) through the UI or the Object Model (as we do above) it won’t be removed when you deactivate the feature unless you write code in the FeatureDeactivated event to do this. You might also want to try the DisplaceOnUpgrade parameter in the taxonomy field definition as Anders mentioned to avoid the update issues if you are having problems with this. Personally I leave the fields in the site on feature deactivation so it does not break things if users have created lists that use these fields.

    Ari Bakker

    29 Jul 11 at 12:22 pm

  15. @JakeJ I’ve deployed and reactivated dozens of times and haven’t been able to reproduce that issue. If you have a set of steps that can be used to replicate the issue please let me know and I’ll look into it further. The only way I’m aware of the duplicate note field problem occurring is when the TextField is not set correctly and/or you use the Update(true) flag when updating the field (which I’m not doing). You might also want to try Anders’ suggestion and use the DisplaceOnUpgrade flag or if it is a development environment rebuild the site collection so you have don’t have broken fields lying around.

    Ari Bakker

    29 Jul 11 at 12:26 pm

  16. Hi Ari. Thanks for responding. I was setting the field.Update(true) flag when updating the field. As I understand, that propagates changes to any lists that implement that field. In my case, this field is in a page content type. I receive the error when creating a new page. I’ll change that flag. I did see Ander’s suggestion after I posted my comment. I’ve added the DisplayOnUpgrade flag. Unfortunately, this is a production system, so I can’t rebuild, but I ran some code to hook up the correct MM field and MM note field together. After that, I manually removed the MM field from the content type and re-added it back. I was able to create a page with the MM field without the error. Thanks again!

    JakeJ

    2 Aug 11 at 7:48 pm

  17. […] However you will need to do a little extra work to provision through a custom list definition. See Ari Bakker’s post for a guide on how to do […]

  18. Thanks for this article…I have a question regarding binding a field to a termset in the store.

    In your FeatureActivated code example, you show only how to assign a termset to the field as…

    field.TermSetId = termSet.Id;

    I have through the UI been able to bind a managed metadata field to a TermCollection…ie. A group of terms beneath the TermSet. I can’t figure out how to do that in code…I tried assigning the id of the root term of the term collection to the field.TermSetId property but it doesn’t seem to take in my testing.

    Anyone with experience in doing this?

    Thanks

    Mike

    1 Sep 11 at 7:50 pm

  19. Just an addendum to my first post…

    Looking at the example above…

    If you look at the section at the bottom of the article called “Example Project”, what I’m trying to do is to bind directly to ‘Pacific’, which is a TermCollection, rather than to ‘Office Locations’ which is the TermSet.

    I’m able to do this through the end-user interface. But can’t get it to stick when assigning in code.

    Thanks Again

    Mike

    2 Sep 11 at 4:33 pm

  20. ANSWER…

    When binding to a term beneath a termset, in addition to assigning the termset ID to field.TermSetId, you also need to assign the ID of the term you are binding to to field.AnchorId.

    Mike

    Mike

    2 Sep 11 at 4:52 pm

  21. @Mike to set the anchor term use the TaxonomyField.AnchorId property. This should be set to the ID of the term (e.g. Pacific) within the term set (e.g. Office Locations) that you want to use.

    [Edit] Looks like you posted the answer at the same time – thanks for sharing.

    Ari Bakker

    2 Sep 11 at 4:53 pm

  22. Thanks for this great article Ari. Been banging my head against a wall for ages around this.

    One thing I had to do to get TaxonomyCatchAll and TaxonomyCatchAllLabel populated with data (and thus get the managed / crawled properties to auto-create) which wasn’t mentioned in the article but was present in your demo project is as follows :

    When you use VS 2010 to create a list def based on your content type with TaxonomyCatchAll and TaxonomyCatchAllLabel, the schema.xml contains references to these fields in (this is OK) but also contains references to them in section. It refers to them as lookups instead of taxonomy. Until I removed these as per your demo project those 2 fields wouldn’t get populated.

    Lee Borlace

    12 Sep 11 at 5:14 am

  23. […] SharePoint 2010 allows you to centrally manage metadata and keywords. In a previous post I covered how to provision a SharePoint 2010 managed metadata field and add this to a content type and a list definition. In this post I will cover how to add these […]

  24. […] – Ari Bakker’s Provisioning SharePoint 2010 Managed Metadata fields […]

  25. when updating the field, the update method must be used with true to propagate the changes through the lists, otherwise the filed will be disabled.

    lupodjam

    7 Oct 11 at 9:12 am

  26. I have been trying to use the process stated above to no avail. My situation is as follows:
    I am trying to define 5 content types in one list definition all of them using one or more managed metadata fields. When submitting a new item using the first content type everything works fine. As soon as I try a second content type the form produces the error: Failed to get value of the “{0}” column from the “Managed Metadata” field type control. See details in log. Exception message: Invalid field name.

    Any help would be appreciated.

    Matthew Bell

    12 Dec 11 at 6:03 pm

  27. Note that if you use the AutoSPInstaller script to install your SharePoint environment you might have an issue with the DefaultKeywordsTermStore property of the TaxonomySession. This issue is documented at http://autospinstaller.codeplex.com/workitem/17200 and offers an alternative PowerShell command that can be used to ensure this property is set correctly.

    Ari Bakker

    12 Jan 12 at 6:16 pm

  28. Ari,
    Would you do anything differently if you wanted to add the Metadata columns to a Publishing content type? In this case, I’m building out a content type that inherits from Page. I’m using a content type binding to bind the content types to a Pages library.

    Thanks!

    George Durzi

    17 Jan 12 at 3:00 pm

  29. @George – You can use the approach above when creating a metadata column to add to a publishing page. Funnily enough I’ve written a post on that – Adding Managed Metadata Fields to SharePoint Publishing Pages

    Ari Bakker

    17 Jan 12 at 9:42 pm

  30. Thanks Ari, I discovered that post after posting my question – thanks so much for putting both of these together.

    After provisioning the columns how you describe in the post, the issue I’m having is that only one of my content types appears in the refinement panel. I posted a question about this on stackexchange if you’d like to see the details about the content types. Thank you!

    http://sharepoint.stackexchange.com/questions/26921/controlling-metadata-search-refiners-in-search-refinement-panel

    George Durzi

    18 Jan 12 at 3:46 pm

  31. @George thanks, I’m glad it helped!

    Ari Bakker

    18 Jan 12 at 10:34 pm

  32. Excellent guide, Ari! Helped me out tons. Wasn’t aware of the CatchAll fields.

    One question, I’ve gotten this to work flawlessly if I activate the features manually, but if I use the exact same feature and try to activate it automatically as part of a site definition I get a TargetInvocationException in the ConnectTaxonomyField method. Specifically, on the line

    TaxonomyField field = web.Fields[fieldId] as TaxonomyField; (my feature is scoped to web instead of site)

    I can use the exact same site definition without the feature in the onet.xml, and everything works fine when I activate the feature manually.

    Any clue as to what could be going on?

    Troy

    8 Feb 12 at 12:47 pm

  33. Seems to be a permissions issue. I found an UnauthorizedAccessException in my log. Following this post

    http://code2life.blogspot.com/2011/10/sharepoint-2010.html

    I changed my web application’s app pool to use the central administration account, and everything went without a hitch. But, surely, that’s not the best solution.

    Troy

    8 Feb 12 at 1:43 pm

  34. Hello, thank you for this tutorial. I’m brand new to managed metadata fields and this is perfect. I’ve followed this example but when I deploy, i keep getting the error “Error occurred in deployment step ‘Activate Features’: Operation is not valid due to the current state of the object.” I’ve researched this over and over, and I’m stumped. Do you happen to know what might be causing this? Thanks, Shaun

    shaun cline

    30 Mar 12 at 4:12 pm

  35. @Shaun are you able to activate the feature manually and/or attach a debugger to the feature receiver and find out what line of code is causing the error?

    Ari Bakker

    3 Apr 12 at 9:40 pm

  36. @Ari Bakker Thanks for the reply Ari. I found a mistake in the EvenReceiver code I did and one other mistake in the C# code. A co-worker of mine got his to work with those corrections so I believe that should do it. I’ll post again once I’m sure.

    shaun cline

    4 Apr 12 at 3:48 pm

  37. I can confirm the issue Matthew Bell posted back in december. However I believe the issue is related to the list definitions rather than the content types.

    For example I have a base content type which has 3 derived content types. All of the derived content types have their own list definitions and list instances. Only 1 list definition works :-/

    (The base content type has the managed metadata fields and the associated note fields and the taxcatchall/label fields)

    I couldn’t find any solution so far. I’m not sure what is going wrong here. Creating standard custom lists and adding any of the content types in question to them works perfectly.

    RS

    5 Apr 12 at 11:33 am

  38. I got it working, i had a scoping issue and had a GUID out of place. It’s all good.

    shaun cline

    6 Apr 12 at 7:07 pm

  39. Ari,
    Thank you for this great post. I found that what you have here is not quite right. Please check out my post about it: “Correctly Provisioning Managed Metadata Columns”
    http://www.elumenotion.com/Blog/Lists/Posts/Post.aspx?ID=152

    –Doug

    Doug Ware

    17 May 12 at 7:13 pm

  40. Hi,

    I am migrating a 2010 site collection to a new site collection and facing a weird problem. Migration went well. Then I created some Managed Metadata columns and content types and assigned it to a document library. I could upload the document and fill the MM columns too but same how TaxCathall column is empty. Is there anything I have to do to get it working? Any help would be really appreciated.

    Ma

    23 Jun 12 at 4:08 am

  41. For anyone having the UnauthorizedAccessException issue when provisioning a custom list definition with taxonomy fields in a sub-site you need to include the following in the taxonomyfieldtype.

    WebId=”00000000-0000-0000-0000-000000000000″
    List=”TaxonomyHiddenList”

    http://social.technet.microsoft.com/Forums/da/sharepointdevelopmentprevious/thread/7301e0c4-8282-4269-b71c-a5d46ef6d073

    Riccardo

    9 Jan 13 at 5:45 pm

  42. Hi, This is an amazing post regarding event recieversa nd managed metadata.

    I would like a little help regarding event recievers, actually i have a document respository with custom folder content types and document content types and both these document types have managed metadata columns. What i want is when a user creates a new folder it should first check whether that folder exists or not. If it exists then update that folder with the new values and if not then it should create that folder.

    Can you suggest some way or any links where i can get some info and approach on how to procedd

    Thanks
    Sourabh

    Sourabh

    24 Jan 13 at 12:17 pm

  43. @Sourabh the first question I would ask is do you really need folders or can you replace these with a metadata column? If you can I’d suggest avoiding folders and using metadata to classify documents instead. If you have a good reason to use folders and have a valid business requirement for building the type of customisation you mention then I’d suggest investigating whether a custom new form template (i.e. the create folder page) would work. The article Creating Custom Form Templates at http://msdn.microsoft.com/en-us/library/aa544142.aspx has information on this.

    Ari Bakker

    29 Jan 13 at 12:46 pm

  44. @Ari Thanks for the Great Article. Do you know if it possible to do the above and deploy columns and content types in a Web scoped feature? ie: to a child (web)site of the site collection. I really want to evenly distribute my elements across the intranet sites rather that dump them all in the root. I have tried but cant make it work without scope the feature to site. (I’m using SP 2013)

    Russell Munro

    11 Jul 13 at 9:31 am

  45. After deploying your example code without error I progressed to make my own column. I generated some GUIDs from an internet site to use for my newTaxonomyFieldType and Note field elements. After several days of vague errors and feature activation fails I replaced the generated GUIDs with GUIDs from an SP 2013 site (different server). And now my new column deploys without failure.

    This doesn’t make sense to me but if it helps someone else, so be it.

    Russell Munro

    16 Jul 13 at 6:22 am

  46. If you are having persistent issues with “greyed-out” metadata field try: replace field.Update() with field.Update(true); (Using SP 2013)

    Russell Munro

    19 Jul 13 at 2:52 am

  47. […] However I could not find why this was happening.  I was following a blog detailing how to Provisioning SharePoint 2010 Managed Metadata fields and could not see where I was straying from his example.   After hours of hunting for the […]

  48. Thank you for a great blogpost!

    I have been struggling with ‘greyed metadata’ field for few hours now. My problem was that metadata column didn’t seem to connect to term set. I checked all the things on this post (and many others) but couldn’t figure out the why… UNTIL!

    I realised that I had all the components (field, content type, list definition and list intance) in the same feature. Event receiver fired of course, but it didn’t update the column that was already in the list instance (since it had been created already, at least I think so).

    Solution was to separate field and content type in one feature (with event receiver) and list instance to another.

    LazyJones

    24 Oct 13 at 10:10 am

  49. […] by Ari Bakker (whose image I’m using above, thanks Ari), Wictor Wilen and Andrew Connell were popular in […]

  50. […] containing a Managed Metadatacolumn. After some googling I found some nice info’s from Ari Bakker. The problem occurs because the Managed Metadata Column creates an additional field named […]

Leave a Reply

*