Filtration for department and include all items back to root


I am using the GET vars to apply filtration (i.e. ?department=technology) so that I only need one page to show different departments, and have set the root to be the company CEO. However, I am having issues getting members of the department to show up as the upper management often don't belong to the same department, but may have many departments reporting to them. They don't have any specific department they belong to. How do I perform filtration and only include anyone leading back to the root?

Hello, Harri.

I'm sorry for the delay with answering you question.

I suggest you the following approach:

  1. pass two parameters to the GET request: one - for department (department), second - for CEO ID (boxId). I use a SharePoint list as a data source so I will pass a list item ID to the latter:
    .../SitePages/OrgChart-Testing.aspx?department=Marketing Department&boxID=1

  2. Use a value of the first parameter in filtration rule:

  3. Use a value of the second one to set a root item dynamically in custom JavaScript:

  4. Here is the result I have:

As you can see, David Navarro is not from Marketing Department.

Thanks for that.
What if it is more than 1 level deep?
There may be 2 or 3 managers (not marketing specific) between the marketing department and the CEO.
I'm also not sure how to use the script on SharePoint profiles.

Do the managers between CEO and a certain department have something in common? Maybe a keyword in their job titles? It's necessary whether find this common parameter that could be easily formalized or specify those managers in additional GET parameters individually.

If none works for you, then you could create a common parameter: just create a custom property in SharePoint user profiles and list in it all related departments for the managers which are between CEO and departments. Then check whether that property contains a department from a GET request with the includes() method.

For example you created a property "RelatedDepartments". The full list of available properties you can find here:


For this example, I use a list as a data source to save time (I don't have properly configured user profiles). The "RelatedDepartments" property is just a single line text column where I listed comma-separated departments:


Then the filtration rule will check whether a box has a certain department from request or the one is among related ones:

return itemData["Department"] == department || itemData["RelatedDepartments"].includes(department);

If you use SharePoint user profiles as a data source, then instead of list item id, you should use a part of user's account name to set a root node: