Performant Solution for Tree Traversal

In my domain model I have the entity Employee and Team. An Employee is part of one Team (Employee_Team association). An Employee can be the manager of a team (Employee_Team_Manager association). The Team entity has a Parent_Team association to itself which allows me to build a tree hierarchy. This setup allows me to map our organisation with employees at different levels of the tree an the respective managers. My challenge now is that for some business processes, the manager of a team should get a list of not only his direct employees but all employees in all child teams (i.e. his tree node and all nodes below). What is the most efficient or most performant way to retrieve this set of employees through a microflow given the source team (or manager)? I'm thinking this will be a recursive problem.
2 answers

Easiest solution I can think of is to create a microflow SUB_GetDirectReports with as input parameters a boolean Recursive, a parameter EmployeeReportsList of Object Employee and a parameter Manager in which you send the Employee for which you want the report. As Output parameter you return a list of Employee.


You create an EmployeeReportResultList, to which you add the employees contained in the input parameter EmployeeReportsList.


Within the microflow you retrieve a list of Employees (e.g. ReportsList) that report to the Manager.

You Loop/iterate through the list to:

a) Add the IteratorEmployee to the EmployeeReportResultList

b) Check if input parameter Recursive is true, if yes, you call the Microflow with Recursive = true, the EmployeeResultList and the IteratorEmployee as manager. When the call returns, you need to assign the complete output ReportsList to the  EmployeeReportResultList and continue the loop

You then return the EmployeeReportResultList in the end event output parameter.


This will recurse the manager and all underlying managers/reports.


You can create a table of Employee and show it in a data grid, in the onclick you call a page that shows the details of the Employee selected. Within the page you add a Data grid that calls a microflow you call DS_GetEmployeeReportsRecursive.

This DS_GetEmployeeReportsRecursive should have an input parameter Employee. Within it you create a list of Employee (let's call it EmptyList) and then call SUB_GetDirectReports passing true to the Recursive parameter and the EmployeeName amd the EmptyList.

In the end event you return a List and set it to the name of the output list from the SUB_GetDirectReoirts 




Happy to hear you could use it as the basis and further improve it. Cool stuff with recursive microflows :-)