Versions Compared

Key

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

In this section you will learn more about Customs Forms.

...

Estimated Time to complete: TBD

Requirements & Solution Author: Petr Rys

...

Product Discount Data Management Custom Form allows users to perform these tasks:

  • Change Data → select a table and change values within the table without adding new rows.

  • Add new Product Group → add a new group, assign it to a product family, and assign all the required discounts for different levels. It is important that the discount for each additional level is greater than or equal to the discount for the previous level; otherwise, the validation process will fail.

  • Add a product family → reassign product groups to reflect a new product family.

  • Add new discount level to existing product family → create new discount levels for an existing product family. The levels must be continuous, starting from level 1 at 0 Min Revenue. Each additional level must have a minimum revenue greater than or equal to the previous level. Users can assign new discounts for these new levels, ensuring that the discount for each additional level is greater than or equal to the discount for the previous level; otherwise, the validation will fail.

...

Expand
titleDive Deeper: Check out a step by step flow of the sample solution video below
  1. To create a standalone custom form, go to the main menu.

  2. Locate the 9 dots icon in the left upper corner of application. Click to open the drop down.

  3. Go to Analytics > Product Discount Manager.

  4. In the new dialogue window, click on Create New Product Discount Manager icon in the top right corner.

  5. Fill in the label then click on the blue Add icon in the bottom right corner of the window.

(tick) You will get a confirmation message in green that the form has been added successfully.

  1. In the following window, under Inputs, select the management option from the drop down menu.

  2. Depending on your choice, continue filling out the remaining fields.

  3. To assign new products, click on the box and choose where you want to assign from the drop-down menu.

  4. Click on Add in the bottom left corner to add discount levels if applicable.

(warning) Note that you may have to check what values are assigned to each level. To avoid missing out any fields, the system displays warning icons which disappear once the field has been filled out.

(info) You can add as many discount levels as you need. Check out our documentation to learn more about discounts.

  1. Click on Recalculate in the upper right corner.

  2. To see a more detailed view of the Calculations, use the arrow on the right side next to the reload icon to open the calculations window. Click on Show to learn more.

  3. To close the dialogue window click on X in the top right corner.

  4. Click Submit in blue in the upper right corner to send your form for approval. A confirmation message in green will appear at the top center of the window.

  5. In the Workflow tab, if you have enough rights for the operation, you can approve the form by clicking on the green checkmark icon. You can also add a reason for both approvals or rejections.

  6. Add your reason, then click Submit. You will get another confirmation message.

(info) If you go to Company Parameters by clicking the third icon from the left in the top right corner, under Categories> Custom Form, you can check your newly created form.

...

CF-Sample Solution.mp4

Step-by-step solution

Develop the logic and test in Studio

...

In this configuration, the first tab is named "details" and uses the "dashboard" icon. It has a name that can be translated using the "Management options" key. The second tab is named "workflow" and uses the "process" icon. It has a name that can be translated using the "Workflow" key. The third tab is named "actions" and uses the "file-check-alt" icon. It has a name that can be translated using the "Todo list" key. The step label itself is also translatable using the "Product Discount Data Management" key.

Pricefx Studio - Create Custom Form Type

Using the Create Custom Form Type feature in Pricefx Studio simplifies the process of creating a Custom Form Type as compared to manual creation through the user interface. To create a custom form type in Pricefx, please follow these steps:

...

Take a look at line 4 and the value of configuratorName, which will be created in the next step.

DEBUGINGDEBUGGING

Make sure to set the proper CustomForm for your logic in the Inputs tab. Run and test the logic afterwards.

...

Code Block
languagegroovy
import net.pricefx.server.dto.calculation.ConfiguratorEntry

// Get value of the first input from the OtionInput.groovy, only if it exists
String selectedType = 
// Use configuratorSwitch method. Pass selectedType as a parameter.

/**
 * This method is used to select and configure different types of ConfiguratorEntries.
 * It also loads the correct messages for each type.
 *
 * @param selectedType The type of ConfiguratorEntry to be used. This could be 'CHANGE_DATA', 'NEW_FAMILY', or 'NEW_GROUP'.
 * @return A ConfiguratorEntry instance configured based on the selectedType.
 * If the getterMethod or message for the selectedType do not exist, the method will return null.
 */
ConfiguratorEntry configuratorSwitch(String selectedType) {
    Script CONFIG_UTILS = libs.sCFO_ProductDiscountLib.CfoConfiguratorUtils
    Script CONST_CONFIG = libs.sCFO_ProductDiscountLib.ConstConfig

    def getterMap = [
            (CONST_CONFIG.CHANGE_DATA) : CONFIG_UTILS.&getChangeDataConfiguratorEntry,
            (CONST_CONFIG.NEW_FAMILY)  : CONFIG_UTILS.&getAddFamilyConfiguratorEntry,
            (CONST_CONFIG.NEW_GROUP)   : CONFIG_UTILS.&getAddGroupConfiguratorEntry,
    ]

    def messageMap = [
            (CONST_CONFIG.CHANGE_DATA) : CONST_CONFIG.CFO_CONFIGURATOR_CONFIG.PARAGRAPH_MESSAGE_CHANGE,
            (CONST_CONFIG.NEW_FAMILY)  : CONST_CONFIG.CFO_CONFIGURATOR_CONFIG.PARAGRAPH_MESSAGE_ADD_FAMILY,
            (CONST_CONFIG.NEW_GROUP)   : CONST_CONFIG.CFO_CONFIGURATOR_CONFIG.PARAGRAPH_MESSAGE_ADD_GROUP,
    ]

    def getterMethod = getterMap[selectedType]
    def message = messageMap[selectedType]

    if (getterMethod && message) {
        return configureEntries(getterMethod, message)
    }
}

/**
 * This method applies configuration to entries.
 *
 * @param getterMethod Method reference for getting configurator entry.
 * @param message The message to be set as paragraph header in configurator entry.
 * @return ConfiguratorEntry The modified configurator entry with new paragraph header.
 */
ConfiguratorEntry configureEntries(def getterMethod, String message) {
    ConfiguratorEntry configuratorEntry = getterMethod.call()
    configuratorEntry.setMessage(message)
    return configuratorEntry
}

EXPECTED RESULT

...

DEBUGGINGDEBUGING

  • Open logic.json in sCFO_ProductDiscountHeader_Configurator.

  • Open Studio Editor.

  • Click on the Inputs tab.

  • Set the Context to CONFIGURATOR.

  • Test Logic

  • Click on the Results tab and check output

...

For Discount Level Definition option:

...

CF-Change Data Discount Level Definition.

...

mp4

For Product Family Mapping option:

...

CF-Change Data Product Family Mapping.

...

mp4

For Discount option:

...

CF-Change Data Discount.

...

mp4

  1. All fields are required.

...

  • Add new Product Group option

...

  1. “New Product Goup“ is an input type of String

  2. “Assign Product Family” is a drop-down list with unique values of Product Familty colum in Discount Level Definition company parameter table.

  3. The table for adding and deleting discount records should have identical columns as the Discount company parameters table, and provide a user-friendly way to add records.

  4. “Product Group” column shoud have a drop-down list with newly added “New Product Group”. ColumnType: Option

  5. “Discount Level” coulumn should have a drop-down list with list of numbers from 1 to 6. columnType: Option

  6. “Traget Discount” and “Max Discount” are coulmns with columnType: Numeric

  7. All fields are required.

...

  1. CF Add

...

  1. New Product Group.

...

  1. mp4

...

  • Add new Product Family option

...

  1. “New Product Family“ is an input type of String

  2. “Assign new Product Family to an already existing Product Group.” is a checkbox. Default: unchecked.

  3. “Assign to:” is a drop-down list. This is a list of unique values from “Product Family” column in Discount Level Definition company parameters table. This filed will be visible if the “Assign new Product Family to an already existing Product Group” value is set to true (with the checkbox checked).

  4. The table for adding and deleting new discount levels records should have identical columns as the Discount Level Definition company parameters table, and provide a user-friendly way to add records.

  5. “Product Family” column shoud have a drop-down list with newly added “New Product Family”. ColumnType: Option

  6. “Discount Level” and “Min Revenue” are coulmns with columnType: Numeric

  7. All fields are required.

scenario1 CF-Add new New Product Family.webmmp4

...

Solution

Go to ChangeDataInputs.groovy and look at the configuratorSwitch method. Implement methods for each option chosen by the user to create one of three forms. Each method returns the ConfiguratorEntry object.

...

  • Assign to: list of unique names from ProductFamilyMapping lookup table

  • New Discount Levels: user can add and delete rows.

...

  • getAddGroupConfiguratorEntry()

...

  • Assign Product Family: list of unique values from ProductFamilyMapping lookup table

  • New Discount: user can add and delete rows

...

Calculations

The results will be displayed as tables in the right panel. Only tables with changes will be shown as copies of parameter tables with updated values.

...

Task

Sample Code

Create a table

Code Block
languagegroovy
ResultMatrix newTable = api.newMatrix('Column_1', 'Column_2',)
newTable.setColumnFormat('Column_1', FieldFormatType.TEXT)
newTable.setColumnFormat('Column_2', FieldFormatType.NUMERIC)

Get data from company parameter table

Code Block
languagegroovy
def getDiscount() {
    def id = api.findLookupTable("Discount").id
    def filters = [ Filter.equal('lookupTable.id', id) ]
    def discountTable = api.find('MLTV2', 0, 0, null, *filters)

    def rows = discountTable.collect {
        [
                productGroup  : it.key1,
                discountLevel : it.key2,
                targetDiscount: it.attribute1,
                maxDiscount   : it.attribute2,
                typedId       : it.typedId]
    }
    return rows
}

How to edit cell style in table

Code Block
languagegroovy
def cell_1 = newTable.styledCell(example_value, "black", "yellow", "bold")
def cell_2 = newTable.styledCell(example_value, "black", "yellow", "bold")
newTable.addRow(cell_1, cell_2)

How to add new table to the customFormProcessor.

Code Block
languagegroovy
customFormProcessor.addOrUpdateOutput(
        [
                "resultName" : "new_name",
                "resultLabel": "new_label",
                "resultType" : "MATRIX",
                "result"     : newTable,
        ]
)

...

Saving changes to the tables

...

We need to ensure that changes in the target tables are displayed accurately. Once the user approves the changes, they should be saved. The customform_WorkflowPosStep logic is responsible for this process.

...