Consider the following scenario
Scenario
- Create a pricelist with the following products and prices.
- Prod1 (Product2):
- Onetime charge - $10(Price)
- 200MBPS (Product2):
- Onetime charge - $10(Price)
- Onetime charge - $500(Price)
- Prod1 (Product2):
As you can see here, 200MBPS has $10 and $500 as one time price. Consider a use case where we can create context rules which validates if Prod1 is part of the cart or not.
- If it is part of the cart, then the price for
200MBPSis $500 - Else, price for
200MBPSis 10$
EPC Setup
Perform the following.
Create a Product Catalog DC1 for the Use Case
- Ensure that catalog has following products.
- Prod1
- 200MBPS
- Create following one time prices for each of the products.
- Prod1
- Onetime charge - $10
- 200MBPS
- Onetime charge - $10
- Onetime charge - $500
- Prod1

Create a Class
- The following class defines context rules function
ProductInOrder, which validates if a given product code is part of the cart or not - Ensure sure to update this class to support managed package by appending
vlocity_cmtfor the following global classes:- VlocityOpenInterface
- CpqCartDocument
- CpqCartDocumentItem
- FlowStaticMap
global with sharing class CtxRuleFunctionApex implements VlocityOpenInterface {
global Boolean invokeMethod(String methodName, Map<String, Object> inputs, Map<String, Object> output, Map<String, Object> options) {
if (methodName == 'ProductInOrder') {
productInOrder(inputs, options, output);
}
return true;
}
//Argument1: ProductCode to be checked
//Output: return true if product exists in the given order else false
public void productInOrder(Map<String, Object> inputMap, Map <String, Object> options, Map<String, Object> outMap) {
List <Object> arguments = (List <Object>) inputMap.get('arguments');
Boolean result = false;
outMap.put('result', false);
if (arguments != null && arguments.size() == 1 && arguments[0] != null) {
String prodCode = (String)arguments[0];
System.debug ('PRODUCT CODE: ' + prodCode);
CpqCartDocument cartDocument = (CpqCartDocument)FlowStaticMap.flowMap.get('cartDocument');
// update result variable based on your conditions
outMap.put('result', result);
}
System.debug('result ---- ' + JSON.serialize(outMap));
}
}
Create a Function-Based Context Rule( Advanced Context Rule)
To add the function definitions in custom metadata, perform the following.
-
Go to Setup.
-
In the Quick Find box, enter custom.
-
Click Custom Metadata Types.
-
Click Function Definition.
-
Click Manage Function Definitions.
-
Click New.
-
Specify settings as follows:
- Label: The function name displayed in the list on the Function Definitions tab.
- Function Definition Name: The unique function name used by the API and managed packages, and which you use in formulas. The name must begin with a letter and use only alphanumeric characters and underscores. The name cannot end with an underscore or have two consecutive underscores.
- ClassName: The Apex class containing the method that implements the logic for the function.
- Method Name: The method that implements the logic for the function.
- Create a function definition in Product Console.
- Define function definition as shown below.
- Define function definition arguments as shown below.
- Create function based context rule as shown below.
- Create advanced context rules condition for above rule as shown below.
- Create ruleset and its children rule assignment as shown below.
- Define function definition as shown below.
Context Rule Assignment
- Assign contextFunctionTest rule set to 500$ onetime charge of 200MBPS product as shown below
Run EPC JOB
Generate EPC Compile data. This job initializes the cache data.
On the EPC Jobs page, click Start next to GENERATE COMPILE DATA. From the Price List dropdown list, select the price lists, and then click Apply
note: Context dimension mappings with functions must be converted to rule conditions with functions.
