Link to home
Start Free TrialLog in
Avatar of Lazaro Rondon
Lazaro Rondon

asked on

Getting direct reports under another manager's direct reports list

I've been trying to figure out how to do this but I'm always met with a bump on the road. What I'm trying to do is to get the reporting people under my manager's direct reports list; so for example, "Alex" is a direct report under my manager, however, when you go into his organization you see that he also has direct reports that report directly to him - I am trying to get "those" reports not only from his side but from anyone else in the list that has direct reports as well. What is needed for me to effectively execute that idea? Many thanks!

This is my code to only get Direct Reports under my manager tree:
    public void GetManagerDirectReports()
        {
            Application App = new Application();
            AddressEntry currentUser = App.Session.CurrentUser.AddressEntry;
            if (currentUser.Type == "EX")
            {
                ExchangeUser manager = currentUser.GetExchangeUser().GetExchangeUserManager();
                if (manager != null)
                {
                    AddressEntries addrEntries = manager.GetDirectReports();
                    if (addrEntries != null)
                    {
                        foreach (AddressEntry addrEntry in addrEntries)
                        {
                            ExchangeUser exchUser = addrEntry.GetExchangeUser();
                            StringBuilder sb = new StringBuilder();
                            sb.AppendLine("Name: "
                                + exchUser.Name);
                            sb.AppendLine("Title: "
                                + exchUser.JobTitle);
                            sb.AppendLine("Department: "
                                + exchUser.Department);
                            sb.AppendLine("Email: "
                                + exchUser.PrimarySmtpAddress);
                            Debug.WriteLine(sb.ToString());
                            Console.WriteLine(sb.ToString());
                            Console.ReadLine();
                        }
                    }
                }
            }
        }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Lazaro Rondon
Lazaro Rondon

ASKER

That is correct Andy, I do indeed need recursion because I need it to loop back to me every time it finds a parent and child. Now, and excuse my dumb question, how do I structure your code snippet in order for me to get the managers and direct reports of those managers?
You have
ExchangeUser manager =
and
ExchangeUser exchUser

so I guess you need to replace MyObject with ExchangeUser
Recursion is needed to loop through children of parent and the children of each child.....