3

For building a CAML query including filters by Managed Metadata Column, I need to get the wssid for terms I've only the unique ID.

I found a lot of examples using C# and Microsoft.SharePoint.Taxonomy.TaxonomyField.GetWssIdsOfTerm, but now example using the JavaScript Object Model.

Is this even possible with JavaScript?

Example

var ctx = SP.ClientContext.get_current();
var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(ctx);
var termStores = taxSession.get_termStores();
var termStore = termStores.getByName('My Termstore');
var currentTermSet = termStore.getTermSet('f71f5e3f-d393-4ad8-a648-b6ca20f2ce75');
ctx.load(currentTermSet);

ctx.executeQueryAsync(
    function () {
        var terms = currentTermSet.get_terms();
        ctx.load(terms);
        ctx.executeQueryAsync(
            function () {
                var termsEnum = terms.getEnumerator();
                while (termsEnum.moveNext()) {
                    var currentTerm = termsEnum.get_current();

                    var termUniqueID = currentTerm.get_id();
                    var termLabel = currentTerm.get_name();
                    // How to get the wssid which is needed for filtering in CAML?      
                }                       
        });
});
  • 2
    Don't think wssid is available from the term in the termset, since the wssid is the ID in the TaxonomyHiddenList in a site collection, meaning the same term could have different wssids in different sites. Guess you could make a function like GetWssidsOfTerm, and query the TaxonomyHiddenList. – Anders Aune Sep 15 '14 at 16:40
2

In JSOM API use SP.Taxonomy.TaxonomyFieldValue.wssId property to get the list item ID of the list item containing the taxonomy field value that is encapsulated by the TaxonomyFieldValue object.

Example

var listTitle = 'Contacts';
var listItemId = 1;
var taxFieldName = 'Country';

var ctx = SP.ClientContext.get_current();
var web = ctx.get_web();
var list = web.get_lists().getByTitle(listTitle);
var item = list.getItemById(listItemId);

ctx.load(item);
ctx.executeQueryAsync(
     function() {
         var taxFieldValue = item.get_item(taxFieldName);
         console.log(taxFieldValue.get_wssId());
     },
     function(sender,args){
        console.log(args.get_message());
     }
);

Note: a single-valued taxonomy field (SP.Taxonomy.TaxonomyFieldValue type) is used in the example

  • Hi, thanks for your reply. This is not what I needed, because I don't want to iterate a list, I only have the terms from a termset. At the moment, I do not have a list item like in your code... I added a code example to my question. :) – Fensterbank Sep 15 '14 at 15:49
  • @Vadim, do you know why when using a no-markup app page, taxonomy field returns this object: SP.Taxonomy.TaxonomyFieldValue { $0_1: "MyTermLabel", $1_1: "23875525-01c7-42ad-9a89-bf4e9dd864de", $2_1: 2}? It is better described in my question sharepoint.stackexchange.com/questions/173401/… Thank you – egidiocs Mar 8 '16 at 20:52
  • @Vadim, How to get the term name by using WSSID or Label from? I want to display term in html page – Mihir Aug 9 '16 at 18:24
0

I'm not sure if this is what you were trying to do, but in my case I was able to filter a Managed Metadata field by simply evaluating it as a text field. No need for the WSSID.

For example if your column is called Category and you want to filter the items tagged with "Meetings" you could do:

<Eq>
    <FieldRef Name="Category" />
    <Value Type="Text">Meetings</Value>
</Eq>

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.