How to Use Column Labels in api.find() and api.stream()
When using the api.find() or api.stream() method in Groovy to search for data, you can reference fields in the fields, sortBy, and filters parameters by either:
Their low-level database field name (e.g.,
sku,clientId,attribute1)Or their configured label (e.g.,
"Product SKU","Customer ID")
Using labels requires extra context: When referencing a label in filters (and sometimes in sortBy or fields), you must also provide a discriminator filter to define the entity in which the label is defined. Without this, the method cannot resolve which field the label refers to and may throw an error.
What Is a Discriminator Filter?
A discriminator filter specifies which configuration context to use when resolving a label to a data field. It is essential when you are using a label instead of a database field name in api.find().
Earlier versions than 14.1 may have returned data "by chance" if only one matching label existed.
Prefer using database system field names (e.g., sku, customerId, claimId) for non-attribute fields = fields that have a specific meaning in Pricefx. To be able to use labels for attribute fields, make sure to include the appropriate discriminator filter.
Discriminator Filters by Type Code
Here is a list of required discriminator filters based on the entity (typeCode) you're querying:
Type Codes | Required Discriminator Filter |
|---|---|
PX, CX, SX |
|
MLTV, JLTV |
|
PGI, XPGI |
|
PLI, XPLI |
|
SIMI, XSIMI |
|
MR |
|
CFO | One of:
|
CRCP, CRCI1, ..., CRCI12 |
|
CLLI |
|
Example Using Label With Discriminator
def filters = [
Filter.equal("name", "PX_Margin"), // discriminator
Filter.equal("CustomerName", "ACME Inc.") // label
]
def result = api.find("PX", *filters)Troubleshooting
Symptom | Likely Cause | Solution |
|---|---|---|
| Label used without discriminator | Use the correct database field or add the required discriminator filter |
No results returned unexpectedly | Ambiguous label resolution | Provide discriminator to clarify context or edit the column labels to remove the ambiguity |
Works on version 13 but not 14.1 and later | Relying on fallback | Update logic to use correct fields or provide discriminator |
See Also
Found an issue in documentation? Write to us.