Restore Modified Attributes
Learning Objectives
After completing this unit, you’ll be able to:
- Implement a rule to restore modified attributes to their original state.
- Create evaluation and qualification entity filters.
Restore Attributes to Their Original State
Earlier in this module, Eliza, the CPQ developer at Infiwave, created an advanced rule to modify the attributes of the Broadband Cable Service product at run time. This protects customers from incompatible attribute choices. However, she soon learns that there’s a glitch in this implementation. When customers remove the product that triggers the attribute modification, the modified attributes don’t return to their original state. Eliza realizes she must create a new rule to restore attributes when removing the product from the Cart.
Take a minute or two to understand the impact of creating rules without having a counter-action rule. Open the same order, with the Broadband Cable Service and Business Video Service products as line items in the Cart. Delete the Business Video Service product from the Cart. Now, open the configuration pane of the Broadband Cable Service product to view the Download Speed picklist values. Notice that the attribute picklist values remain modified even though you removed Business Video Service. It only lists 200 Mbps as the available download speed. This is because the actual underlying JSON structure is modified.
To paraphrase Sir Isaac Newton’s Third Law, for every action that changes something in the Cart, there must be an equal and opposite reaction. As a matter of cosmic history, it’s easier to destroy than to create, and this is no different.
Create the Product Relationship
As mentioned earlier, Eliza must create a rule that restores the amended product to its original state. She starts by cloning the existing Business Video Modifies Broadband Cable Attributes product relationship and renames it Business Video Restores Broadband Cable Attributes. This new product relationship performs actions to restore all the original Download Speed attribute values.
Follow along with Eliza in your training playground.
- From the Product Relationships view, select Business Video Modifies Broadband Cable Attributes.
- In the product relationship header, click
and select Clone.
- In the New Product Relationship page, change these details.
- In the Product Relationship Name field, enter
Restore Broadband Cable Attributes
.
- For Product, select Broadband Cable Service.
- For Related Product, delete Broadband Cable Service.
- In the Action Parameters field, change all the instances of
exclude
toinclude
in the existing code.
- In the Product Relationship Name field, enter
- Save your changes.
You have successfully created a product relationship that restores the Broadband Cable Service product’s modified attributes.
Create Entity Filters
Entity filters create the context for rules by filtering order line items and searching for defined conditions. Entity filters consist of one or more conditions that evaluate fields or attributes on an object and, if true, apply a rule action. This rule action can be a product relationship, a matrix, a calculation, or a procedure. Rules can contain one filter or many filters, depending on the business logic that the rule implements.
For example, a filter to identify premises with a service activation date of 45 days or less. Filters are reusable and additive. Once created, they are available for use in any rule.
In this section, you work with two types of entity filters: evaluation and qualification entity filters.
Create an Evaluation Entity Filter
With her new product relationship in place, Eliza realizes the tricky part—she needs the product relationship to trigger only when Business Video Service doesn’t exist in the Cart. As it turns out, checking for the nonexistence of something is more difficult than checking for its existence. To fulfill the requirement, she creates a compound entity filter that chains an evaluation entity filter with a qualification entity filter.
You don’t use evaluation entity filters directly in rule building. Instead, they are internal filters to qualification entity filters. You soon learn how. These entity filters evaluate if all, any, or none of the record sets satisfy certain conditions. They accept a list of items as input and return true or false as the output. For example, an evaluation filter evaluates to true if any of the product’s children has a maximum quantity of less than ten and a minimum quantity larger than two.
Here’s how you create an evaluation entity filter to test for Business Video Service in each line item of the Cart.
- From the App Launcher, find and select Vlocity Entity Filters.
- Click New.
- In the New Vlocity Entity Filter page, provide these details.
- In the Entity Filter Name field, enter
EVAL Is Business Video a line item
.
- For Filter On Object Name, select Order Product<OrderItem>.
- For Type, select Evaluation.
- In the Valid From field, select today’s date.
- For Evaluation Criteria, select None.
- Save your changes.
- In the Entity Filter Name field, enter
Here, you set the Evaluation Criteria as None to specify the criteria in which the filter must return True. In this case, it says that if none of the line items are Business Video Service, all the line items have satisfied the condition and thus can be passed directly to the rules engine.
Next, chain the new evaluation entity filter to a qualification entity filter that prepares the list of input items for evaluation and, when true, passes the list of qualified items to the rules engine. Here’s how you create the conditions for the entity filter.
- In the EVAL Is Business Video a line item page, under Entity Filter Conditions, click Add.
- For the Field/Attribute/Related Object field, click Select.
- In the Field Selection window, select Price Book Entry ID, and then select Product Name<Name>.
- Save your changes.
- For Operator/Field, select =.
- In the Value field, enter
Business Video Service
.
- Save your changes.
Create a Compound Qualification Entity Filter
A compound filter acts on the order items, returning the item if the entity filter condition is true. The filter condition is the evaluation filter you created earlier. In other words, the filter returns a list of items from the Cart named Business Video Service.
Here’s how to create the compound filter.
- In the Vlocity Entity Filters page, click New.
- In the New Vlocity Entity Filter page, provide these details.
- In the Entity Filter Name field, enter
Check Cart for Business Video
.
- For Filter On Object Name, select Order Product<OrderItem>.
- For Type, select Qualification.
- In the Valid From field, select today’s date.
- Save your changes.
- In the Entity Filter Name field, enter
Next, you create the conditions for the entity filter.
- Under Entity Filter Conditions, click Add.
- For Type, select Function.
- For Field/Attribute/Related Object, select Items in cart.
- For Value, enter
EVAL
and select EVAL Is Business Video a line item.
- Save your changes.
You have successfully created both your entity filters.
Create and Test the Advanced Rule
With the product relationship and entity filters in place, it's time to connect the dots by creating an advanced rule that restores the modified attributes of the Broadband Cable Service Product to their original state.
- From the App Launcher, find and select Vlocity Rules.
- Click New.
- In the New Vlocity Rule page, add these details.
- In the Rule Name field, enter
Attribute Reverse Mods Actions Rule
.
- In the next line, for the three dropdowns, select Configuration, Order Product<OrderItem>, and Active respectively.
- In the Rule Name field, enter
Next, add the product relationship that appears as actions within the Vlocity Rule Builder.
- In the Filters And Actions List, click Actions to view all the product relationships.
- Locate Restore Broadband Cable Attributes, and click Add To Rule Action.
- To improve the reusability of this rule, add the Check Cart for Business Video filter as a modifier for the Restore Broadband Cable Attributes action.
- Under Filters And Actions List, click Filters.
- Next to FILTERS in the search box, enter
check
.
- Click the Check Cart for Business Video filter and drag it over the Restore Broadband Cable Attributes action. The filter now displays as an action modifier.
- Under Filters And Actions List, click Filters.
- Save your changes.
By using the filter as a modifier to the action, you increase the reusability of this rule. You can add multiple actions to this one rule, and each action only triggers for records qualified by the attached filter.
Test the Rule in the Cart
It’s time to test whether the advanced rule works as desired. As a best practice, run the necessary maintenance jobs after creating the rule.
- Open the same order that you created in the last unit. This order contains both the Business Video Service and Broadband Cable Service products.
- From the Broadband Cable Service action menu, select Configure.
- Click Download Speed. You see only one picklist value, 200 Mbps.
- Close the configuration window.
- Delete the Business Video Service product from the Cart.
- Then, open the configuration window of the Broadband Cable Service product.
Notice that all the Download Speed attribute picklist values have been restored. Mission accomplished!
In this unit, you used evaluation and qualification entity filters to create advanced rules and reverse attribute modification. Next, move on to create advanced rules for Auto-Add relationship type.