---
title: "Filter WQL by Org Hierarchy and workersByRole Safely"
description: "Use workersByRole on workersForHCMReporting in WQL to filter workers by organization hierarchy, and guard endpoints with exclude so non-role users do not error."
url: https://kiweely.com/guides/wql-organization-hierarchy-filter-workersbyrole
---

# Filtering WQL Queries by Organization Hierarchy and workersByRole Without Throwing Security Errors

To return workers in an HR Partner’s assigned organizations and subordinate hierarchies, use workersForHCMReporting with dataSourceFilter = workersByRole. Guard the endpoint with an exclude check so users without the constrained role do not trigger a hard WQL error.

-   **Checked** against Workday on November 6
-   Applies to **Workday Query Language**
-   3 min read
-   Published November 6
-   By Kiweely

## Replicating HR Partner Hub organization hierarchy filtering in WQL

When building a manager or HR Partner dashboard in Workday Extend, filtering a staffing or worker data source with `WHERE ON worker manager_Level01 IN (<% me %>)` only returns direct reports of the logged-in user. It does not return workers across the Supervisory Organizations, Cost Center Hierarchies, or subordinate reporting trees where the logged-in user holds a constrained role such as **HR Partner**, **HR Executive**, or **Compensation Partner**.

To retrieve all workers across the organizations (and subordinate organization hierarchies) assigned to the current user’s role, use the `workersForHCMReporting` data source with the `workersByRole` data source filter and pass the Role-Based Security Group `workdayID` in the `roles` parameter:

sql

```
SELECT workdayID AS id,
       legalFullName AS descriptor,
       supervisoryOrganization,
       organizationAndSuperiorOrganizations
FROM workersForHCMReporting (
  dataSourceFilter = workersByRole,
  roles = (daccab9f1d250156228972696b57e0a5),
  removeExcludeFromHeadcount = false,
  active = true,
  includeTerminatedWorkers = false
)
```

Because `workersByRole` evaluates Workday’s organization role assignments natively on the data source, it automatically includes workers in both the directly assigned Supervisory Organizations and any subordinate organizations inherited down the hierarchy, matching the population shown in the delivered **HR Partner Hub**.

## Guarding `workersByRole` against hard errors for non-role personas

The `workersByRole` data source filter has a strict runtime prerequisite: if a user who does **not** hold the specified role-based security group (or does not have access to run `workersByRole`) opens the Presentation Metadata (`PMD`) page under `authType: "sso"`, Workday throws a hard endpoint error that blocks the entire page from rendering.

To prevent the page from crashing when accessed by general employees, line managers, or other personas, split the lookup into two chained inbound endpoints in your `.pmd` file:

1.  **Endpoint 1 (`workerRoleCheck`):** Query `workersForHCMReporting (dataSourceFilter = allActiveWorkers)` for the logged-in user (`workerDataSelf.id`) and select a True/False Calculated Field (`cf_CFTFRoleIsHRPartner`) that evaluates whether the current worker holds the target role.
2.  **Endpoint 2 (`workersInSupportedOrgs`):** Add an `"exclude"` property bound to `<% !workerRoleCheck.data[0].cf_CFTFRoleIsHRPartner %>` so the `workersByRole` query is skipped whenever the logged-in user does not hold the role.

json

```
{
  "endPoints": [
    {
      "name": "workerDataSelf",
      "baseUrlType": "workday-staffing",
      "url": "workers/me",
      "authType": "sso"
    },
    {
      "name": "workerRoleCheck",
      "baseUrlType": "WORKDAY-WQL",
      "url": "<% '/data?query=' + string:urlEncode('SELECT worker, cf_CFTFRoleIsHRPartner FROM workersForHCMReporting (dataSourceFilter = allActiveWorkers) WHERE worker IN (' + workerDataSelf.id + ')') %>",
      "authType": "sso"
    },
    {
      "name": "workersInSupportedOrgs",
      "exclude": "<% empty(workerRoleCheck.data) || !workerRoleCheck.data[0].cf_CFTFRoleIsHRPartner %>",
      "baseUrlType": "WORKDAY-WQL",
      "url": "<% '/data?query=' + string:urlEncode('SELECT workdayID AS id, legalFullName AS descriptor FROM workersForHCMReporting (dataSourceFilter = workersByRole, roles = (daccab9f1d250156228972696b57e0a5), removeExcludeFromHeadcount = false, active = true, includeTerminatedWorkers = false)') %>",
      "authType": "sso"
    }
  ]
}
```

## Querying Cost Center, Cost Center Hierarchy, GL Account, and GL Account Hierarchy in WQL

When building financial or organization prompt dropdowns (`instanceList` widgets) on an Extend page, individual organizations and organization hierarchies live in separate WQL data sources and organization types:

1.  **Cost Centers and Cost Center Hierarchies:** Both Cost Centers and Cost Center Hierarchies can be queried from `topLevelOrganizations` (or `organizations`) by filtering `type1` (Organization Type) to the tenant’s `Organization_Type_ID` WID for **Cost Center** versus **Cost Center Hierarchy**, or by querying `costCenterHierarchies` / `costCenters` reporting data sources directly:

sql

```
-- Individual Cost Centers via topLevelOrganizations
SELECT workdayID, name, code, type1
FROM topLevelOrganizations
WHERE type1 IN ('<Cost_Center_Organization_Type_WID>')

-- Cost Center Hierarchies via topLevelOrganizations
SELECT workdayID, name, code, type1, superiorOrganization, subordinateOrganizations
FROM topLevelOrganizations
WHERE type1 IN ('<Cost_Center_Hierarchy_Organization_Type_WID>')
```

1.  **Ledger Accounts and Ledger Account Summaries (GL Account Hierarchies):** Individual GL accounts are queried from `ledgerAccounts`. To query GL Account Hierarchies (Ledger Account Summaries), use the `ledgerAccountSummaries` data source or convert a custom report built on the **Ledger Account Summary** business object using the **Convert Report to WQL** task:

sql

```
-- Individual GL Accounts
SELECT workdayID, ledgerAccount, ledgerAccountName, ledgerAccountTypes
FROM ledgerAccounts

-- GL Account Hierarchies (Ledger Account Summaries)
SELECT workdayID, ledgerAccountSummary, superiorLedgerAccountSummary
FROM ledgerAccountSummaries
```

If you are unsure which WQL alias corresponds to a specific hierarchy data source or organization type WID in your tenant, create a 2-column custom report on that business object in Workday and run **Convert Report to WQL** to copy the exact `FROM` data source alias, `dataSourceFilter`, and `Organization_Type` WID.

## How to verify the fix in your tenant

1.  Run **Convert Report to WQL** on a test report using the **Workers for HCM Reporting** data source and the **Workers by Role** filter to obtain your tenant’s exact Role-Based Security Group WID for `roles = (...)`.
2.  Proxy in as an **HR Partner** who holds that constrained role and open your Extend page. Confirm that `workersInSupportedOrgs` executes and returns workers from both the directly assigned Supervisory Organizations and their subordinate organizations.
3.  Proxy in as a standard employee who does not hold the HR Partner role and open the same page. Confirm that `workerRoleCheck.data[0].cf_CFTFRoleIsHRPartner` evaluates to `false`, `workersInSupportedOrgs` is excluded cleanly, and the page loads without throwing a WQL access error.

## Sources checked

-   [FROM Clause in WQL](https://doc.workday.com/admin-guide/en-us/reporting-and-analytics/custom-reports-and-analytics/workday-query-language-wql-/wql-reference/kba1611189724822.html)
-   [PARAMETERS in WQL](https://doc.workday.com/admin-guide/en-us/reporting-and-analytics/custom-reports-and-analytics/workday-query-language-wql-/wql-reference/trh1644452418127.html)
-   [Convert Reports to WQL Queries](https://developer.workday.com/documentation/GUID-5f67ee19-8585-4606-a077-9bd6ffc55532-enHYPHENus)
-   [endPoints](https://developer.workday.com/documentation/ujr1530565661647)
-   [Reference: WQL REST API](https://developer.workday.com/documentation/GUID-5c940864-7651-4e28-a9d2-79b45292e66a-enHYPHENus)

## Related guides

[All guides](https://kiweely.com/guides)

-   [### Fixing Graph API DataSourceFilter Is Inaccessible Errors and Blank processingWorker Fields When Proxying Workday Graph API queries fail with DataSourceFilter is inaccessible when the caller lacks View access to the domain securing the filter, and silently return blank fields on processingWorker when Employee As Self lacks contact domain permissions.](https://kiweely.com/guides/workday-graphql-datasourcefilter-inaccessible-processingworker-proxy)
-   [### Why fileLength on workerDocuments Returns 52 in WQL for Business Process Attachments Querying fileLength on the workerDocuments related business object in WQL returns a constant 52 (or 0) whenever the document was attached through a business process event. Retrieve the actual byte length in Workday Orchestrate using Data.contentLength().](https://kiweely.com/guides/wql-workerdocuments-filelength-returns-52)
-   [### Escaping Single Quotes for Multi-Value IN Clauses and Fixing Double URL-Encoded Unicode in PMD WQL Dynamic WQL queries in Workday Extend PMD fail when comma-separated attribute strings are wrapped in a single pair of quotes or when instanceListQuery is double URL-encoded. Split and quote each ID individually, and call string:urlDecode(instanceListQuery) before building the WQL string.](https://kiweely.com/guides/wql-pmd-single-quote-escaping-double-urlencoded-unicode)
-   [### Why WQL Queries on findCandidates and allWorkers Return Empty Right After a Business Process Step WQL queries triggered during a Workday business process often return zero rows for two distinct reasons: the transaction has not committed yet, or the query reads an eventually consistent indexed data source like findCandidates. Trigger on Completed status or pass launch parameters directly.](https://kiweely.com/guides/wql-indexing-delay-findcandidates-bp-status-change)

### More guides on WQL

[All 31 guides](https://kiweely.com/guides#wql)

-   [Fixing WQL Error 804 on GROUP BY and Related Business Object Aggregation Limits](https://kiweely.com/guides/wql-group-by-error-804-rbo-aggregation-limits)
-   [Fixing WQL Error “Empty Required Parm Moment\_Parm” with SUM()](https://kiweely.com/guides/wql-empty-required-parm-moment-parm-sum)
-   [Fixing WQL “Cannot construct instance source on grouped results” with COUNT(DISTINCT)](https://kiweely.com/guides/wql-count-distinct-with-where-on-rbo-filter)
-   [Why WHERE fieldA = fieldB Throws “Invalid Where Clause” in WQL](https://kiweely.com/guides/wql-compare-two-fields-where-clause-invalid)
-   [Filtering Empty Related Business Objects in WQL and Guarding Omitted RBO Keys in PMD](https://kiweely.com/guides/wql-check-rbo-empty-missing-json-keys-pmd)
-   [Fixing WQL “Specify a valid report field” and HTTP 500 Errors When an ISU Queries Calculated Fields](https://kiweely.com/guides/wql-calculated-field-isu-specify-valid-report-field-500)
-   [Why WQL AVG() Rounds to Whole Numbers and How to Handle Conditional Logic Without CASE](https://kiweely.com/guides/wql-avg-integer-rounding-conditional-logic-without-case)
-   [WQL 500-Instance Related Business Object Limit and Large IN (...) Filter Limits](https://kiweely.com/guides/wql-500-rbo-instances-per-row-large-in-filter-limits)

### From the blog on WQL

[All posts](https://kiweely.com/blog)

-   [Answering Executive Span-of-Control and Headcount Questions Live from Workday](https://kiweely.com/blog/executive-org-span-of-control-attrition-questions-live-workday)
-   [Build vs. Buy a Workday MCP Server: OAuth 2.1, SOAP, WQL, and Twice-Yearly Releases](https://kiweely.com/blog/build-vs-buy-workday-mcp-server-engineering-cost)
-   [What happens after ChatGPT writes your WQL query](https://kiweely.com/blog/after-chatgpt-writes-your-wql)

## Let Workday check the work.

Kiweely writes WQL and builds orchestrations in your own tenant, and Workday, not Kiweely, says whether they passed.

[Start for free](https://kiweely.com/download) [See how it works](https://kiweely.com/vine/how-it-works)

## Get the next guide in your inbox.

One email a month with new guides and one Extend tip. Nothing else.
