7. Modify Line Item Key on the Fly

Prerequisites

Step 0: Task

I calculate cost differently for every customer group. I have only a few customer groups and tens of customers. I do not want to create tens of entries for every product. On algorithmical level, I need to know the following:

  • What is the PX column name where Customer Group is stored?

  • How to match a specific Customer Name to a proper Customer Group?

Step 1: Prepare Lookup Configuration

To implement the above information, we will:

  • Change key2Field with the name of the PX column where Customer Group is stored. We will be using Customer Group. In our case, the new column is called CustomerGroupColumn.

  • Create a logic which handles transformation from Customer Name to Customer Group.

    • Create a Groovy library logic. Create a function within that logic which:

      • Accepts one parameter which will be secondaryKey of a line item. In our case it will be Customer Name.

      • Returns the transformed value – in our case Customer Group.
        Example:

        def getCustomerGroup(String secondaryKey) { if (secondaryKey.startsWith("Cust-1")) { return "CUSTOMER_GROUP_1" } return "CUSTOMER_GROUP_GENERAL" }
  • Put the path to the above function in the key2Transformation field.

    • The format is: libs.LibraryName.ElementName.FunctionName

    • In our case it is: libs.TransformationLibrary.Utils.getCustomerGroup

image-20240603-145010.png

Fields:

  • key1Transformation/key2Transformation – Path to the function which can transform PGI/PLI key into a different lookup value. It is useful when the data has plain structure (not hierarchical), but it is less granular than line items.

 

Step 2: Call Lookup Library

Calling lookup library has not changed from the previous cookbook.

Step 3: Read Results

Reading results has not changed since the previous cookbook.