Enumerate through all items RRS feed

  • Question

  • Greetings,

    How can I modify the code in C# below to return all the classification enumerations, including "children of children" categories?

    // Create a list of all classification items by the parent guid
    ManagementPackEnumerationCriteria mpenumcriteriaChildrenOfIncidentCategoryParent =
      new ManagementPackEnumerationCriteria("Parent = '1f77f0ce-9e43-340f-1fd5-b11cc36c9cba'");
    IList<ManagementPackEnumeration> listenumIncidentCategory =
    SelectList categoryList = new SelectList(listenumIncidentCategory, "Id", "DisplayName");



    Wednesday, October 15, 2014 5:20 PM

All replies

  • Use the GetChildEnumerations() method with TraversalDepth.Recursive. I'll use the ServiceRequestArea enumeration in the example below (since it has multiple child levels by default)

    Guid gServiceRequestAreaEnumeration = new Guid("3880594C-DC54-9307-93E4-45A18BB0E9E1"); //ServiceRequestArea enumeration
    IList<ManagementPackEnumeration> lstAllServiceRequestAreaEnumerations = emg.EntityTypes.GetChildEnumerations(gServiceRequestAreaEnumeration, TraversalDepth.Recursive);

    Be aware that this method "flattens" the list of enumerations. So even children of children will be in "lstAllServiceRequestAreaEnumerations". In other words, the enumeration hierarchy is not maintained. However, each enumeration still has a reference to its immediate Parent Id (via the Parent property).

    Since I used ServiceRequestArea in my example, you can just replace 3880594C-DC54-9307-93E4-45A18BB0E9E1 with 1f77f0ce-9e43-340f-1fd5-b11cc36c9cba

    Wednesday, October 15, 2014 7:20 PM