none
How do I get the guids of taxonomy/metadata terms for updating lists?

    Question

  • I'm integrating a legacy system with SP2010 using a literal SOAP calls. I can do a call such as CopyIntoItems or UpdateListItems and doing so, set metadata fields by providing a Fields node such as:

      <Fields>
           
    <FieldInformation Type="Note" DisplayName="Country_0"
                             
    Id="de1e6424-7a8a-42a5-8d21-73402fe2e609"
                             
    Value="UK|91c89925-16e6-4d41-9e71-ec45e8f2a113" />
           ...
     
    </Fields>

    In the Value attribute, I have to give the guid of the taxonomy or metadata term. That works fine in the above example since I happen to know the guid of the term UK. However, how can I dynamically figure out what the guid of some other value, say France for example, would be? I was thinking of making a utility to get them all and cache them on my system somehow so I can look them up easily, but where are they defined?

    Monday, February 21, 2011 3:22 PM

Answers

  • They are defined in the Managed Metadata SharePoint database. You can find them using the object model. Here is some code I use to get the Guid of a term used in a user property (p). You will probably have to change it depending on how you get to the TermSet object.

    TermSet

     

     

    ts = p.CoreProperty.TermSet;

    TermCollection

     

     

    terms = ts.GetTerms(label, true);

     

     

    if (terms != null)

    {

     

     

    Term term = terms[0];

     

    guid = term.Id

     

    }

    You can also retrieve them from the database. Query by a colleague of mine:

    select ECMGroup.Name as GroupName , ECMTermSet.Name as TermSetName, ECMTermLabel.Label, ECMTerm.UniqueId

    from

     

    dbo.ECMGroup

    left

     

    outer join dbo.ECMTermSet on ECMGroup.Id = ECMTermSet.GroupId

    left

     

    outer join dbo.ECMTermSetMembership on ECMTermSetMembership.TermSetId = ECMTermSet.Id

    left

     

    outer join dbo.ECMTerm on ECMTerm.Id = ECMTermSetMembership.TermId

    left

     

    outer join dbo.ECMTermLabel on ECMTermLabel.TermId = ECMTerm.Id

    where

     

    ECMGroup.Type = 0

    order

     

    by ECMTermSetMembership.Path

    Or you can use the data stored in the hidden TaxonomyHiddenList (for tags used in a given site collection): http://<server>/<root>/lists/TaxonomyHiddenList

    • Marked as answer by James Hedley Tuesday, March 01, 2011 10:01 AM
    Monday, February 21, 2011 3:59 PM
  • You could always write a simple web service that your external system can talk to for getting this information, that would allow you to use full native object model as shown above.


    SharePoint 2010 Extensions - http://sp2010ext.codeplex.com/ My Blog - http://www.withinsharepoint.com Twitter - http://twitter.com/#!/withnsharepoint
    • Marked as answer by James Hedley Monday, February 21, 2011 5:35 PM
    Monday, February 21, 2011 5:22 PM

All replies

  • They are defined in the Managed Metadata SharePoint database. You can find them using the object model. Here is some code I use to get the Guid of a term used in a user property (p). You will probably have to change it depending on how you get to the TermSet object.

    TermSet

     

     

    ts = p.CoreProperty.TermSet;

    TermCollection

     

     

    terms = ts.GetTerms(label, true);

     

     

    if (terms != null)

    {

     

     

    Term term = terms[0];

     

    guid = term.Id

     

    }

    You can also retrieve them from the database. Query by a colleague of mine:

    select ECMGroup.Name as GroupName , ECMTermSet.Name as TermSetName, ECMTermLabel.Label, ECMTerm.UniqueId

    from

     

    dbo.ECMGroup

    left

     

    outer join dbo.ECMTermSet on ECMGroup.Id = ECMTermSet.GroupId

    left

     

    outer join dbo.ECMTermSetMembership on ECMTermSetMembership.TermSetId = ECMTermSet.Id

    left

     

    outer join dbo.ECMTerm on ECMTerm.Id = ECMTermSetMembership.TermId

    left

     

    outer join dbo.ECMTermLabel on ECMTermLabel.TermId = ECMTerm.Id

    where

     

    ECMGroup.Type = 0

    order

     

    by ECMTermSetMembership.Path

    Or you can use the data stored in the hidden TaxonomyHiddenList (for tags used in a given site collection): http://<server>/<root>/lists/TaxonomyHiddenList

    • Marked as answer by James Hedley Tuesday, March 01, 2011 10:01 AM
    Monday, February 21, 2011 3:59 PM
  • Hi, thanks very much for the response and the information.

    As I say I'm only able to use literal SOAP calls since this integration is with a non-Windows platform so the first 2 methods aren't possible. The TaxonomyHiddenList looks promising since I can get that via a regular HTTP GET. Only problem is that it only presents tags that are already used, as you pointed out.

    Hmmm, I know they get GUIDS before they are used, so it would be the answer *if* I could get those in advance, as it were. Is that possible?

    Monday, February 21, 2011 4:52 PM
  • You could always write a simple web service that your external system can talk to for getting this information, that would allow you to use full native object model as shown above.


    SharePoint 2010 Extensions - http://sp2010ext.codeplex.com/ My Blog - http://www.withinsharepoint.com Twitter - http://twitter.com/#!/withnsharepoint
    • Marked as answer by James Hedley Monday, February 21, 2011 5:35 PM
    Monday, February 21, 2011 5:22 PM
  • I think that's probably a good call. Thanks!
    Monday, February 21, 2011 5:35 PM