Versions Compared

Key

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

...

If you want to link to a page within the Pricefx application, it is best to use ResultMatrix.linkCell(). This will ensure that the link that the end user clicks points to a valid page within the same frontend application. Otherwise, there will be issues if the URL changes. For example, if the customer migrates from the Classic frontend application to Unity, all links would still be pointing to Classic.

Tip
For a full list of pages that can be targeted with ResultMatrix.linkCell(), see the reference.
Code Block
languagegroovy
themeMidnight
titlehttps://github.com/pricefx/example-configuration/tree/main/pricefxSrc/CalculationLogic/Dashboard_Chart_Examples/elements/TableWithInternallLinks.groovy
linenumbersfalse
ResultMatrix tableWithCustomerDetail(
        List<Map> data,
        Map<String, String> labels
) {
    def table = api.newMatrix()

    def allLabels = labels + [openCustomerDetail: 'Customer Detail']

    table.withColumns(allLabels.keySet())

    def rows = data.collect { dataRow ->
        // Add a field to the data set
        dataRow + [
                openCustomerDetail: customerDetailLink(table, dataRow.customerId)
        ]
    }

    table.withRows(rows)

    // Add labels to the columns
    allLabels.each { name, label ->
        table.withColumnTranslation(name, ['': label])
    }

    return table
}

String customerDetailLink(ResultMatrix table, String customerId){
    // If customerId is null, the customer master table screen would open
    if(customerId == null){
        throw new Exception('customerId must be provided')
    }
    return table.linkCell('Customer Detail', 'customersPage', customerId)
}

...