Result Fields and Sort Order

Overview

The resultFields and sortBy attributes on <filter> elements let you control which fields are returned and in what order. Using resultFields improves performance by requesting only the columns you need, reducing network transfer and memory usage. Using sortBy ensures deterministic ordering, which is important for paginated exports.

Complete XML Examples

resultFields for Selective Data Retrieval

Only fetch the fields you actually need:

XML
<filters>
    <filter id="productSkuAndLabel" resultFields="sku,label">
        <and/>
    </filter>
</filters>

sortBy for Ordered Results

Sort results by a specific field:

XML
<filters>
    <filter id="sortedProducts" sortBy="sku">
        <and>
            <criterion fieldName="label" operator="notNull"/>
        </and>
    </filter>
</filters>

Combining resultFields and sortBy

XML
<filters>
    <filter id="exportFilter" sortBy="id"
            resultFields="update_action,Key,Attr1,Op1,Val1,PriceType,AdjType,AdjValue,AmtCurrency,ValidFrom,ValidTo">
        <and/>
    </filter>
</filters>

resultFields with Criteria

Fetch only specific fields for products matching certain conditions:

XML
<filters>
    <filter id="activeProductSummary" resultFields="sku,label,attribute1,attribute2" sortBy="sku">
        <and>
            <criterion fieldName="attribute1" operator="notNull"/>
            <criterion fieldName="label" operator="notNull"/>
        </and>
    </filter>
</filters>

Incremental Export with LAST_UPDATED Sort

A common pattern for tracking incremental exports — sort by the update timestamp:

XML
<filters>
    <filter id="fetchOneRecordForTimestamp" resultFields="LAST_UPDATED" sortBy="LAST_UPDATED">
        <and>
            <criterion fieldName="LAST_UPDATED" operator="notNull"/>
        </and>
    </filter>
</filters>

How It Works

  1. resultFields — a comma-separated list of field names to include in the fetch response. Only these columns are returned from Pricefx, reducing payload size.

  2. sortBy — specifies the field to sort results by. The sort direction is ascending by default.

  3. Both attributes are set directly on the <filter> element alongside the id.

  4. At runtime, these values are passed as headers (filter-resultFields and filter-sortBy) to the Pricefx API, which includes them in the fetch request.

  5. When using batchedMode=true, sortBy is critical for ensuring consistent pagination — without it, records may be duplicated or skipped across batches.

Common Pitfalls

  • Missing fields in resultFields: If you specify resultFields but forget a field that your mapper needs, the mapper will receive null for that field. Always ensure resultFields includes all fields referenced in your mapper.

  • sortBy with batched mode: When using batchedMode=true, always specify sortBy. Without deterministic ordering, pagination can produce duplicate or missing records.

  • Field name case: Field names in resultFields and sortBy are case-sensitive and must match the exact Pricefx field names (e.g., sku not SKU for master data, but LAST_UPDATED for DataSource fields which may be uppercase).

  • Performance: resultFields significantly reduces response size for objects with many attributes. Always use it when you only need a subset of fields.

  • Comma in field names: Field names in resultFields are comma-separated with no spaces. Adding spaces may cause field name mismatches.