function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
paul-lmipaul-lmi 

Pulling DataCategories via WebServices API returns them out of order

I'm following the datacategory code samples in C# from the webservices API doc. When pulling them back, they don't seem to be in any sane order, as defined in the setup area. Since all that is return is a DataCategory[], and a DataCategory itself only has properties for name, label, and description, I'm a little perplexed here.

 

*werewolf**werewolf*

Can you be more specific?  What order are you looking for them to be in?

paul-lmipaul-lmi

i'm looking for them to be in the order that i define them in the SF Setup area.

 

Example, in our environment, I have a data category called Products.  They are defined in order:

LogMeIn Rescue

LogMeIn Central

LogMeIn Pro2

LogMeIn Backup

LogMeIn Hamachi2

LogMeIn Free

LogMeIn Ignition for iPhone

LogMeIn Ignition for Android

LogMeIn Ignition for Windows

RemotelyAnywhere

Network Console

join.me

 

And when I pull the datacategories via the API, this is the order I get them in a seemingly random order.  While writing this, I got:

LogMeIn Backup
LogMeIn Ignition for iPhone
LogMeIn Hamachi2
LogMeIn Ignition for Windows
LogMeIn Free
LogMeIn Rescue
RemotelyAnywhere
Network Console
LogMeIn Pro2
LogMeIn Ignition for Android
LogMeIn Central
join.me

 

When I wrote the original post, they were in a different order.

 

Here's the code I'm using to pull the data categories (C# .NET)

 

    /// <summary>
    /// getProducts returns a StringDictionary (Map) of products where each item is key=productcode, value=product name
    /// <example>
    /// foreach(DicitionaryEntry d in getProducts()){
    ///     Debug.Writeline("productcode is: " + d.key + " Product is: " + d.value);
    /// }
    /// </example>
    /// </summary>
    /// <returns>A StringDictionary of key-value pairs representing the products list</returns>
    public StringDictionary getProducts()
    {
        //first, check the app cache for the StringDictionary, if found, return this instead of calling API
        StringDictionary cachedproducts = (StringDictionary)HttpContext.Current.Cache["knowledgeproducts"];
        if (cachedproducts != null) 
        {
            Debug.WriteLine(DateTime.Now + " - " + "KnowledgeUtils" + " - " + "Cache used for products");
            return cachedproducts; 
        }

        //create a container list to put the product datacategories in
        List<DescribeDataCategoryGroupStructureResult> productlist = new List<DescribeDataCategoryGroupStructureResult>();

        //define the datacategorygroupSobjectType and group name
        DataCategoryGroupSobjectTypePair pair = new DataCategoryGroupSobjectTypePair();
        pair.sobject = "KnowledgeArticleVersion";
        pair.dataCategoryGroupName = "Products";

        //Salesforce requires this to be passes as a collection
        DataCategoryGroupSobjectTypePair[] pairs = new DataCategoryGroupSobjectTypePair[] {pair};

        //get the data categories
        DescribeDataCategoryGroupStructureResult[] results = binding.describeDataCategoryGroupStructures(pairs, false);

        for (int i = 0; i < results.Length; i++)
        {
            DescribeDataCategoryGroupStructureResult singleresult = results[i];
            productlist.Add(singleresult);
        }

        //now we'll put the datacateogries in a stringdictionary for easier code use
        StringDictionary products = new StringDictionary();

        foreach(DescribeDataCategoryGroupStructureResult a in productlist){
            DataCategory[] toplevelcats = a.topCategories;
            

            for (int j = 0; j < toplevelcats.Length; j++)
            {
                DataCategory singlecat = toplevelcats[j];
                Debug.WriteLine(DateTime.Now + " - iterating cat: " + singlecat.name);
                string catname = singlecat.name;
                if (catname == "AllProducts")
                {
                    DataCategory[] children = singlecat.childCategories;

                    for (int x = 0; x < children.Length; x++)
                    {
                        Debug.WriteLine(DateTime.Now + " - adding cat: " + children[x].name);
                        products.Add(children[x].name, children[x].label);
                    }
                }

            }
           
        }

        //cache the products list so this doesn't require an API call every time
        HttpContext.Current.Cache.Insert("knowledgeproducts", products);

        //finally, return the StringDictionary
        return products;     
    }

 

I'll note, that the caching doesn't matter here, this happened before I implemented that.

etienne.giraudyetienne.giraudy

Paul,

Categories should come back in the correct order. There is probably a bug behind the behavior you are seeing.

Can you enter a case for this?

Thanks

Etienne

paul-lmipaul-lmi

Hi Etienne,

 

Case 04255306 has been opened per your recommendation.

 

Thanks!