0

Can anyone help me in looping through the Terms. I have 4 Level Terms

for ex:

    NType - 1

    State - 1

      Jurisdiction - 1

         Agency Name - 1
         Agency Name - 2

      Jurisdiction - 2

         Agency Name - 1
         Agency Name - 2

    State - 2

      Jurisdiction - 1

         Agency Name - 1
         Agency Name - 2

      Jurisdiction - 2

         Agency Name - 1
         Agency Name - 2

 NType - 2

    State - 1

      Jurisdiction - 1

         Agency Name - 1
         Agency Name - 2

      Jurisdiction - 2

         Agency Name - 1
         Agency Name - 2

    State - 2

      Jurisdiction - 1

         Agency Name - 1
         Agency Name - 2

      Jurisdiction - 2

         Agency Name - 1
         Agency Name - 2

and it goes on. 'N' number of NTypes same with the the states or any other level.

In this scenario, can I at least loop through the terms and print them as they are in the TermStore?

I am not sure its possible. I tried several ways. Looping through is giving problems.

Its getting executed in very a sync model. Any outer loop is not waiting for its child loop. Not synchronous.

1

If I understand you correct, you want to load all the items independently. I suppose you are asking about how to do it javascript, and Client Object Model. Is it correct?

If so you have two options:

  1. Define all the items you want to load, and then invoke context.executeQueryAsync. See my other answer in this forum.

  2. Load items using promises or provide callback as an anonymous functions inside a loop. I answered a similar question where I tried to explain how to use callbacks in javascript and how to load multiple items in an async way.

Hope this helps to start to investigate.

  • Hey, Thanks for your reply. But what i want exactly is to be able to load the TermStore and print in the order as they are stored in the TermStore. In the same order. for example the structure you see in my question. First load all NType - 1 utems before go to NType - 2. TO do that load State - 1 first, then its childern Jutisdiction - 1 its childern AgencyName - 1 and Agency Name - 2 then Jurisdiction - 2 and its children. so on. In normal case with any other synchronous loops we will have 4 level nested loops to print it right? – Naveen Jun 28 '13 at 3:57
  • but here as i have just async execution method i am not getting the correct terms in correct order. No outer loop is waiting for its inner loop to finish. – Naveen Jun 28 '13 at 4:01
  • You could wait for every item to be loaded, then load another one. It is not so difficult, if you know how to work with multiple callbacks On the other hand, you should use the built-in order. Your items should have index (perhabs CustomSortOrder in Termstore) that you could use to put the links in the right place, no matter in what order they come from server. – Anatoly Mironov Jun 28 '13 at 6:31
  • 1
    Had you tried using Promises – nbi Jul 19 '15 at 20:35

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.