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 | ||
---|---|---|
| ||
You will get a confirmation message in green that the form has been added successfully.
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. You can add as many discount levels as you need. Check out our documentation to learn more about discounts.
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. |
...
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 | ||
---|---|---|
| ||
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:
...
...
For Product Family Mapping option:
...
...
For Discount option:
...
...
All fields are required.
...
Add new Product Group option
...
“New Product Goup“ is an input type of String
“Assign Product Family” is a drop-down list with unique values of Product Familty colum in Discount Level Definition company parameter table.
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.
“Product Group” column shoud have a drop-down list with newly added “New Product Group”. ColumnType: Option
“Discount Level” coulumn should have a drop-down list with list of numbers from 1 to 6. columnType: Option
“Traget Discount” and “Max Discount” are coulmns with columnType: Numeric
All fields are required.
...
...
...
...
Add new Product Family option
...
“New Product Family“ is an input type of String
“Assign new Product Family to an already existing Product Group.” is a checkbox. Default: unchecked.
“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).
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.
“Product Family” column shoud have a drop-down list with newly added “New Product Family”. ColumnType: Option
“Discount Level” and “Min Revenue” are coulmns with columnType: Numeric
All fields are required.
...
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 tableNew Discount Levels: user can add and delete rows.
...
getAddGroupConfiguratorEntry()
...
Assign Product Family: list of unique values from
ProductFamilyMapping
lookup tableNew 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 |
| |||||
Get data from company parameter table |
| |||||
How to edit cell style in table |
| |||||
How to add new table to the customFormProcessor. |
|
...
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.
...