Try this:
Code |
---|
Query = New Query;
Query.Text =
"SELECT
| Departments.Ref AS Department,
| Employees.Description AS HeadFullName
|FROM
| Catalog.Departments AS Departments
| LEFT JOIN InformationRegister.DepartmentHeads.SliceLast(&Period, ) AS DepartmentHeadsSliceLast
| ON DepartmentHeadsSliceLast.Department = Departments.Ref
| LEFT JOIN Catalog.Employees AS Employees
| ON DepartmentHeadsSliceLast.Head = Employees.Ref
|
|ORDER BY
| Departments.Ref HIERARCHY";
Query.SetParameter("Period", CurrentDate());
QueryResult = Query.Execute();
YourTreeObject = FormAttributeToValue("YourTree");
YourTreeObject = QueryResult.Unload(QueryResultIteration.ByGroupsWithHierarchy);
ValueToFormAttribute(YourTreeObject, "YourTree"); |
By the way, I changed joins order: the Departmens catalog should go first: when there is no head of department yet, this department will not be displayed.