Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagegroovy
import net.pricefx.common.api.FieldFormatType

def productList = null

List<String> fields = ["ProductId", "label", "ProductGroup", "currency", "BusinessUnit", "ProductClass", "Size", "ProductLifeCycle" ]

productList = api.find("P", 0, api.getMaxFindResultsLimit(), "ProductId", fields)

def columnFormats = [
        "ProductId": FieldFormatType.TEXT,
        "label": FieldFormatType.TEXT,
        "ProductGroup": FieldFormatType.TEXT,
        "currency": FieldFormatType.MONEY_EUR,
        "BusinessUnit": FieldFormatType.TEXT,
        "ProductClass": FieldFormatType.TEXT,
        "Size": FieldFormatType.TEXT,
        "ProductLifeCycle": FieldFormatType.TEXT,
]

def rows = productList

def resultMatrix = api.newMatrix()
        .withColumnFormats(columnFormats)
        .withRows(rows)
        .withGroupBy(['BusinessUnit'])
        .withGroupBy(['ProductGroup'])
        .withGroupBy(['Size'])

return resultMatrix

Result

Aggregation Example

In the following example we retrieve the data from the Product Extensions table. We apply group by Currency column and then aggregate SUM on ListPrice column.

Code

Code Block
languagegroovy
import net.pricefx.common.api.FieldFormatType

import static net.pricefx.server.dto.calculation.ResultMatrixGrouping.AggregateFunctionType
import static net.pricefx.server.dto.calculation.ResultMatrixGrouping.AggregateFunctionType.SUM

def filter = [
        Filter.equal("name", "ListPrice"),
]

List<String> fields = ["ProductId", "ListPrice", "Currency"]

def listPriceItems = api.find("PX3", 0, api.getMaxFindResultsLimit(), "ProductId", fields, *filter)

def rows = listPriceItems

def columnFormats = [
        "ProductId": FieldFormatType.TEXT,
        "ListPrice": FieldFormatType.MONEY,
        "Currency" : FieldFormatType.MONEY,
]

def resultMatrix = api.newMatrix()
        .withEnableClientFilter(true)
        .withColumnFormats(columnFormats)
        .withRows(rows)
        .withGroupBy(['Currency'])
        .withColumnAggregation('ListPrice', SUM)
        .calculateGroupByData()

return resultMatrix

Result