0

We need to get all the normal keywords inside the abstract keywords: for example we have 2 normal keywords hotelA and HotelB:

  • hotel(category)
  • United States (abstract keyword)
    • North Dokota (abstract keyword)
      • Fargo(abstract keyword)
        • HotelA (normal keyword)
        • HotelB (normal keyword)

How can we get keyword of hotelA and HotelB using the tcm id of United States using coreservice client?

5
  • Binod , Can you please share your tridion version if possible.
    – Anand N S
    May 4, 2021 at 11:34
  • Also - what did you try thus far? What challenges are you experiencing? May 4, 2021 at 12:07
  • currently we are using tridion version 8.5 @AnandNS
    – Binod
    May 4, 2021 at 12:20
  • we are trying to get the hotel information using country keywords @Dylan..MarkSaunders
    – Binod
    May 4, 2021 at 12:22
  • What I mean, @Binod, is can you indicate what interaction you've already tried with the Core services? was it prompted from other suggestions in TREX, from Blogs etc.? what results did it yield? May 5, 2021 at 13:23

2 Answers 2

1

In general, to get a list of items related to some subject, you can use the Core Service methods GetList (returns Data Objects) or GetListXml (returns so-called R5 XML).

Specifically, to get a list of child Keywords, you use one of those methods in combination with a filter of type ChildKeywordsFilterData.

If you only want to get the "normal"/"concrete" (i.e. not abstract) Keywords, you can specify ChildKeywordsFilterData.IsAbstract = false.

2
  • as we need to find the normal keyword nested inside another abstract keywords ChildKeywordsFilterData will only get the keywords inside level one only
    – Binod
    May 11, 2021 at 14:47
  • Ah, you want to get the entire subtree. Indeed, you'll have to do a recursive method like shown in the other Answer. As of Tridion Sites 9.6, it will be possible to retrieve an entire Taxonomy in one go. That is: it is possible to retrieve a list of all Keywords (KeywordsFilterData), including their parent/child relationships. May 17, 2021 at 6:56
0

the solution which i have written will be a recursive function which is not effective but it works.

public static IEnumerable<XElement> getChildKeywords(string tcmId)
            {
                var normalkeywordFilter = new ChildKeywordsFilterData() { IsAbstract = false };
                var normalKeywords = client.GetListXml(tcmId, normalkeywordFilter).Elements().ToList();
    
                if (normalKeywords.Count() != 0) return normalKeywords;
    
                var allabstractKeywords = con.client.GetListXml(tcmId, new ChildKeywordsFilterData() { IsAbstract = true }).Elements().ToList();
                foreach (var el in allabstractKeywords)
                {
                    normalKeywords.AddRange(getChildKeywords(el.Attribute("ID").Value).ToList());
                }
    
                return normalKeywords;
            }

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.