Skip to content
KiweelyKiweelyKiweely

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
  • Applies to Workday Query Language
  • 3 min read
  • Published
  • By Kiweely
On this page

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

Related guides

All guides

Let Workday check the work.

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

Get the next guide in your inbox.

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

We’ll email you once to confirm. Unsubscribe in one click from any issue.