---
title: "Filtering Empty RBOs in WQL and Omitted Keys in PMD"
description: "Fix WQL error \"can only be used as a related business object field (RBO)\" when checking for empty RBOs, and safely guard omitted empty RBO JSON keys in PMD."
url: https://kiweely.com/guides/wql-check-rbo-empty-missing-json-keys-pmd
---

# Filtering Empty Related Business Objects in WQL and Guarding Omitted RBO Keys in PMD

Checking whether a context-linked Related Business Object (RBO) is empty in a WQL WHERE clause can throw “Field: ... can only be used as a related business object field (RBO)”, and empty RBOs are omitted entirely from WQL JSON responses. Learn how to filter empty RBOs and guard PMD scripts.

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

## Why `WHERE <rbo> IS NOT EMPTY` Throws `can only be used as a related business object field (RBO)`

When replicating a Custom Report that has both a top-level filter and a subfilter on a Related Business Object (RBO)—or even when running Workday’s **Convert Report to WQL** task—you may end up with a WQL statement that checks `WHERE <rbo> is not empty` in the Primary Business Object (PBO) `WHERE` clause:

sql

```
SELECT employeeID, allowancePlans_{effectiveDate} AS allowancePlans_
FROM allActiveAndTerminatedWorkers (effectiveAsOfDate = '2026-09-30')
WHERE ON allowancePlans_
  cf_ZCFGlobalTFEligibleForNextMonthsProgram = true
  AND compensationPlan IN (8eba4afa96061001aa36f4c60f050000)
WHERE
  allowancePlans_ IS NOT EMPTY
  AND cf_GLobalTFEmployeeIsActiveInNextMonth = true
  AND activeStatus = true
```

Executing this query on `allActiveAndTerminatedWorkers` or `workersForHCMReporting` fails with the error:

text

```
Field: allowancePlans_ can only be used as a related business object field (RBO)
```

Yet if you simply delete `allowancePlans_ IS NOT EMPTY` from the `WHERE` clause, the query no longer excludes workers who have zero matching `allowancePlans_` instances—returning the entire active worker population (for example, 130,000 workers instead of the 314 workers who actually hold that allowance plan).

### Root Cause: Context-Linked Fields vs. Standard Instance Fields

Look closely at the trailing underscore in `allowancePlans_` and inspect its field description in Workday:

> *“Provides the context link between the worker and compensation plan assignment business objects. This field specifically provides a link to the allowance plans assigned to an employee. Linked fields cannot be used in reports as fields, and should only be used as related business objects in reports.”*

Standard multi-instance fields on a PBO can be evaluated in `WHERE field IS NOT EMPTY`. Context-linked RBO bridges (which often end in `_`, such as `allowancePlans_` or `meritPlans_PlanDetails`) are not report fields on the PBO; they exist solely as RBO traversal links for `SELECT rbo{...}` and `WHERE ON rbo ...`. Even though **Convert Report to WQL** mechanically translates the report filter into `WHERE allowancePlans_ IS NOT EMPTY`, the WQL validator rejects context-linked bridges inside the `WHERE` clause.

### Fix: Extract Single Instance (ESI) or Extract Multi-Instance (EMI) Calculated Field on the PBO

To filter the PBO population so only workers with a matching RBO instance are returned:

1.  Create a **True/False Condition** calculated field on the **Related Business Object** (`Compensation Plan Assignment`) that evaluates your subfilter criteria (`cf_ZCFGlobalTFEligibleForNextMonthsProgram = true` and `compensationPlan IN (...)`).
2.  Create an **Extract Single Instance (ESI)** or **Extract Multi-Instance (EMI)** calculated field on the **Primary Business Object** (`Worker`) that extracts from the `Compensation Plan Assignment` relationship using the True/False Condition from Step 1.
3.  Because the ESI/EMI calculated field (`cf_workerEligibleAllowancePlan`) is a first-class report field on `Worker`, reference it directly in the PBO `WHERE` clause:

sql

```
SELECT employeeID, allowancePlans_{effectiveDate} AS allowancePlans_
FROM allActiveAndTerminatedWorkers (effectiveAsOfDate = '2026-09-30')
WHERE ON allowancePlans_
  cf_ZCFGlobalTFEligibleForNextMonthsProgram = true
  AND compensationPlan IN (8eba4afa96061001aa36f4c60f050000)
WHERE
  cf_workerEligibleAllowancePlan IS NOT EMPTY
  AND cf_GLobalTFEmployeeIsActiveInNextMonth = true
  AND activeStatus = true
```

## Why Empty RBO Fields Disappear from WQL JSON Responses in PMD

When your WQL query intentionally returns PBO rows whose RBO collection may or may not have values—for example, querying work experience credentials alongside optional `employmentDocumentation` attachments—WQL exhibits a second behavior that catches PMD developers off guard:

sql

```
SELECT
  startEmploymentDate,
  endEmploymentDate,
  employer,
  jobTitle,
  academicAppointee,
  employmentDocumentation{workdayID AS id, fileName AS descriptor, documentType}
FROM instructorEligibilityCredentials_dnqbzb_workExperienceEligibilityCredentials
WHERE academicAppointee IN ('734428758077011554686b58e64dfd24')
```

When a row has no `employmentDocumentation` records, **WQL’s JSON serializer completely omits the `employmentDocumentation` key from that row object** rather than emitting `"employmentDocumentation": []` or `"employmentDocumentation": null`:

json

```
{
  "total": 1,
  "data": [
    {
      "startEmploymentDate": "2015-01-01",
      "endEmploymentDate": "2019-12-31",
      "employer": "PSC",
      "jobTitle": "Faculty",
      "academicAppointee": {
        "descriptor": "Alex Rivera",
        "id": "734428758077011554686b58e64dfd24"
      }
    }
  ]
}
```

If a PMD script or grid cell template attempts to index `row.employmentDocumentation[0].documentType` or check `row.employmentDocumentation.documentType` without first checking whether the parent key exists on `row`, the page crashes at runtime because `row.employmentDocumentation` is undefined.

### Fix: Guard Both the Parent RBO Array and Child Property with `empty`

In PMD scripting, the unary `empty` operator safely evaluates `null`, `undefined` (omitted JSON keys), empty strings `""`, and zero-length arrays `[]` in a single check. Always short-circuit on `empty row.<rboName>` before indexing `[0]` or traversing a nested property:

javascript

```
for (var row : getCredentials.data ?? []) {
  if (empty row.employmentDocumentation || empty row.employmentDocumentation[0].documentType) {
    // Key was omitted or array is empty — prompt user to attach documentation
    row.hasDocument = false;
  } else {
    // Safe to read row.employmentDocumentation[0].documentType
    row.hasDocument = true;
    row.docTypeDescriptor = row.employmentDocumentation[0].documentType.descriptor;
  }
}
```

Inside a PMD grid `cellTemplate` expression, you can also use optional chaining (`?.`) or a ternary with `empty`:

json

```
{
  "type": "text",
  "id": "docTypeCell",
  "value": "<% empty row.employmentDocumentation ? 'Missing Attachment' : row.employmentDocumentation[0].documentType?.descriptor %>"
}
```

## How to Verify in the Tenant

1.  Run your query in **View WQL Query Result**. If WQL rejects `WHERE <rbo> IS NOT EMPTY` with `can only be used as a related business object field (RBO)`, inspect the field definition in Workday to confirm whether it is a context-linked RBO bridge, then replace the PBO check with an ESI/EMI calculated field on the PBO.
2.  Compare the `total` row count in **View WQL Query Result** against your reference Custom Report to verify that PBO rows without matching RBO records are excluded when intended.
3.  For queries where the RBO is optional, inspect the raw JSON payload in **REST API Explorer** for a record with no RBO instances, confirm the RBO key is omitted from the JSON object, and verify that your PMD page loads those rows cleanly using `empty row.<rboName>`.

## Sources checked

-   [Concept: Related Business Objects in WQL](https://developer.workday.com/documentation/GUID-5295e235-6d69-4b80-ad51-510afbdfb853-enHYPHENus)
-   [WQL Reference: WHERE](https://developer.workday.com/documentation/GUID-a9f9f945-baf1-4a7d-9118-db9a8ce49265-enHYPHENus)
-   [WQL Reference: WHERE ON](https://developer.workday.com/documentation/GUID-b3109af0-2d98-4e5f-8806-5d4cd7ccace9-enHYPHENus)
-   [Convert Reports to WQL Queries](https://developer.workday.com/documentation/GUID-5f67ee19-8585-4606-a077-9bd6ffc55532-enHYPHENus)

## Related guides

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

-   [### Fixing WQL “Cannot construct instance source on grouped results” with COUNT(DISTINCT) Combining SELECT COUNT(DISTINCT field) with a WHERE ON Related Business Object (RBO) filter in WQL throws “Invalid WQL query: Cannot construct instance source on grouped results.” unless the PBO WHERE clause also includes WHERE <rbo> IS NOT EMPTY.](https://kiweely.com/guides/wql-count-distinct-with-where-on-rbo-filter)
-   [### WQL 500-Instance Related Business Object Limit and Large IN (...) Filter Limits WQL enforces a strict limit of 500 instances per multi-instance Related Business Object (RBO) on a single row and fails with S24 Internal Error when filtering large IN (...) lists of 200–600+ Workday IDs. Learn how to invert the PBO, filter by hierarchy, or use RaaS.](https://kiweely.com/guides/wql-500-rbo-instances-per-row-large-in-filter-limits)
-   [### What is Workday Query Language (WQL), and how do you write and run a query? Workday Query Language (WQL) is Workday’s SQL-like language for reading data from data sources and fields instead of reports. You need the Workday Query Language domain in the System functional area; an external caller also needs an API client with System scope.](https://kiweely.com/guides/workday-wql)
-   [### Why does my Workday WQL query fail? The exact error messages and how to fix each one Workday has no WQL message worded ‘instance set invalid for prompt’. A rejected prompt value returns ‘Invalid Parameter Values for parameter’ or ‘does not meet the restrictions defined for this field’. This page quotes each common error as Workday returned it, with the fix.](https://kiweely.com/guides/wql-error-messages)

### More guides on WQL

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

-   [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)
-   [Fixing WQL HTTP 400 “Parms are required for the fields or data source in the query”](https://kiweely.com/guides/wql-400-parms-are-required-for-fields-or-data-source)
-   [Custom Agent Actions that call Workday SOAP, REST and WQL](https://kiweely.com/guides/workday-custom-agent-actions-soap-rest-wql)
-   [Running WQL in Orchestrate as an integration system user: the security it needs](https://kiweely.com/guides/workday-orchestrate-wql-as-isu)
-   [WQL Cheat Sheet: Workday Query Language Syntax, Data Sources and Working Examples](https://kiweely.com/guides/workday-wql-cheat-sheet)
-   [Workday Prism Analytics vs. WQL vs. Custom Reports: Joining External and Tenant Data](https://kiweely.com/guides/workday-prism-analytics-vs-wql)
-   [Should I use RaaS, WQL or the REST API to extract data from Workday?](https://kiweely.com/guides/workday-raas-wql-rest)

### From the blog on WQL

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

-   [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)
-   [Answering Executive Span-of-Control and Headcount Questions Live from Workday](https://kiweely.com/blog/executive-org-span-of-control-attrition-questions-live-workday)

## 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.
