1. Most Basic Scenario
Step 0: Task
I want to create the most simple cost lookup which will be batched. On algorithmical level, we need to know the following:
Identifying table:
What is the type of table?
What is the name of table?
What are columns we are looking for:
What is the name of a column with SKU?
What is the name of a column with Cost?
Step 1: Prepare Lookup Configuration
Let's put the information from Step 0 to the LookupConfiguration table:
Fields:
Name – Identifier of the Lookup operation. Here we called it
CustomCost
.userSourceType – Type of the table. LookupConfiguration has been tested with PX/PP/PCOMP tables. Here, we are using
PX
.key1Field – Column name or attributeId. Value of that column needs to match key1 of the current context. In PLI and PGI, key1 is always SKU. In PX, this column name is not editable, so we need to put there
sku
(lowercase - that is the name of the PX column).selectedFields – Map in JSON format. Keys of this map will be referenced in the code. After the lookup is performed, there will be record’s data in these keys in Groovy Map. Values match either ColumnNames or atributeIds. In our case we will refer to our looking value as “cost” and it should be looked up from a column called “CostColumn” – this the input
{"cost":"CostColumn"}
.IsUsingDependencyLevelHierarchy – Allows you to turn on and off (
Yes
/No
) fallback on parent Dependency Levels. This is used for integration of complex PSP mechanism. In this simple scenario, we are turning the fallback off.
Step 2: Call Lookup Library
Put this anywhere in your code before you need to use your cost value:
libs.ConfigurableLookupsLib.LookupInstanceFromPP.prepareConfiguredLookup("CustomCost")
The above code handles all database operations for the whole batch. In a more advanced scenario, you will also pass to this function elementName (for debugging purposes) and dependency config (if using DependencyLevelHierarchy).
Step 3: Read Results
Reading entry does not invoke database calls:
Map lookupResult = libs.ConfigurableLookupsLib.LookupInstanceFromPP.getFirstEntry("CustomCost").
You will find your value from "CostColumn" under the key you defined.
BigDecimal customCost = lookupResult?.cost //lookupResult might be null if there is no entry at all