0

I am trying to get terms by multiple custom properties via JSOM. For example: i have a term with always two custom properties

TABLENAME
DB_ID

I want to query a TermSet or filter a TermCollection by these two custom propertiey like (only as example for explanaition)

SELECT TERMS FROM TERMSET_A WHERE CUSTOMPROP.TABLENAME = "tbl_A" AND CUSTOMPROP.DB_ID = 25

I found the following code

      static Term GetTermByCustomID(string customid)
      {
          Term retTerm = null;

          CustomPropertyMatchInformation matchinfo = new CustomPropertyMatchInformation(Program.clientContext);
          matchinfo.CustomPropertyName = "ID";
          matchinfo.CustomPropertyValue = customid;
          matchinfo.TrimUnavailable = false;

          var terms = termSet.GetTermsWithCustomProperty(matchinfo);
          Program.clientContext.Load(terms);
          Program.clientContext.ExecuteQuery();

          if (terms.Count > 0)
          {
              retTerm = terms[0];
          }

          return retTerm;

      }

But this allows me only to query the TermSet by one custom property key/value combination. I also looked at the MSDN for a description of CUSTOMPROPERTYMATCHINFOMRATION(c), but also this seems not to be possible.

Perhaps someone had this problem, too, and could solve it via JSOM?

0

You can use the function below to get customproperties for a termset in JSOM. The code you mention in your question is more CSOM right? You can make the same method but a little deeper to get customproperties for a specific term. I have a termset "Language" with custom properties.

<script>
$(document).ready(function () {    
    var scriptbase = "YOURURL/_layouts/15/";       
    $.getScript(scriptbase + "SP.Runtime.js", function () {    
        $.getScript(scriptbase + "SP.js", function () {    
            $.getScript(scriptbase + "SP.Taxonomy.js", function () {
                 //Call your code here.
                 getTermsWithCustomProperties();    
            });    
         });   
    });    
    function getTermsWithCustomProperties(){
        var context = SP.ClientContext.get_current();
        var taxonomySession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
        var termStore = taxonomySession.getDefaultSiteCollectionTermStore();
        var termSets = termStore.getTermSetsByName("Language", 1033);
        var termSet = termSets.getByName("Language");
        context.load(termSet);
        context.executeQueryAsync(function onSuccess() {
            var termSetItem = termSet.getTermsWithCustomProperty("TABLENAME");
            var properties = termSetItem.get_objectData().get_properties()["CustomProperties"];
            console.log(properties);
        }, function onFailure(args) {
            alert('Error: '+args);
        });
    }
});
</script>

Regards,

  • Hi DiscoPlacid, thanks for your code but what i am searching for is not to get the custom properties for a specific term instead i need to find the term by its two specified custom properties. – BOG Dec 3 '15 at 15:39
  • Hi, Ok sorry, I understood a little bit later :) There is a function, as you mentioned below to get terms with custom property in the sp.taxonomy.js ex : var termSetItem = termSet.getTermsWithCustomProperty("TABLENAME"); var properties = termSetItem.get_objectData().get_properties()["CustomProperties"]; I tries it but without specific result. You can call the function on the session, on the termstore or on a termset I've updated the code above, maybe you will be luckier than me :) – DiscoPlacid Dec 3 '15 at 17:02

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.