Defining Context Eligibility Rules
The instructions in this topics explain how to apply context eligibility rules.
Configure anonymous and known-user browsing for the anonymous and known-user browsing use case
Perform the following steps to create the context dimension.
- Click App Launcher.
- Search for Vlocity Product Console and click the link.
- Click Dashboard, then click Rules, then click Context Dimension.
- Click New.
- Enter the required information for anonymous users or logged-in users. You do not set different context dimensions for anonymous and logged-in users. One contextdimension works for both, for example:
Field | Description |
---|---|
Name | DC_RULE_FIBER |
Code | DC_RULE_FIBER Code must be the same as Name. |
Data Type | Text |
Domain Type | Type in |
Cacheable Mode | Enable this field |
Default Value | TRUE |
Values for caching | True, False When you run the Populate API Cache job,these values are part of pre-warming the cache. This means the API will return all the products for the defined rule and warm the cache so whenever you get a request that says DC_RULE_FIBER=True, the response is readily available because you ran the Populate API Cache job. If false, the response will also be readily available. If values for caching are provided when running the Populate API Cache job, then records are created in the cache response object. If there are no values in the Values for caching field, there is a cache miss, and when the rule is executed, the response is subsequently created. The values will then be in the cache so there will be a cache hit the next time the API GET request is made. |
- Click Save.
- Click the Context Mapping facet to identify Context Scope.
- Click New Context Mapping.
- Enter the following required information.
For anonymous users (example):
Field | Description |
---|---|
Context Scope | AccountScope. NOTE: Context Mappings with InitializationType as Type In only work with AnyScope or AccountScope ContextScopes. |
Initialization Policy | Always Reinitialize |
Always Reinitialize | Type in For anonymous browsing, you specify the rule criteria by defining a context dimension name.The dimension name does not need to be a field on the account record. To do this, selectType in, which allows the user to pass any context dimension value as part of the criteria to satisfy the rule condition. If you want to use that criterion as part of a known-user scenario, for example, the customer's location, then identify the field on the context scope object, in this case, the account object. |
TypeIn Value | DC_RULE_FIBER It is recommended that you give the TypeIn Value the same name as the ContextDimension. The TypeIn Value must be a constant value that you want the context dimension to hold. Context Mappings with Initialisation Type as TypeIn only work with AnyScope or AccountScope Context Scopes. |
Sequence | 1 |
For logged-in users (example):
Field | Description |
---|---|
Context Scope | AccountScope. NOTE: Context Mappings with InitializationType as Type In only work with AnyScope or AccountScope Context Scopes. |
Initialization Policy | Always Reinitialize |
Initialization Type | Source Expression |
Source Expression | DC_RULE_MEMBER_STATUS__c This identifies the logged-in user contextcondition. For known users, the Rule Engine looks for a field named DC_RULE_MEMBER_STATUS__c on the Account Object to request context information about the user. For example, the logged-in user who is browsing products has a Gold-member SLA. "DC_RULE_MEMBER_STATUS" is the ContextDimension and "Gold" is the Context Value that is passed as part of the API Request. |
Sequence | 1 |
- Click Save.
Perform the following steps to create the context rule.
- Click App Launcher.
- Search for Vlocity Product Console and click the link.
- Click + icon next to the Rules item in the menu.
- Enter the following required information. For anonymous users (example):
Field | Description |
---|---|
Name | DC_RULE_FIBER_AVAILABLE |
Code | DC_RULE_FIBER_AVAILABLE |
Expression Mode | or |
For logged-in users (example):
Field | Description |
---|---|
Name | DC_RULE_MEMBER_STATUS |
Code | DC_RULE_MEMBER_STATUS |
Expression Mode | or |
- Click Save.
- Click Rule Condition.
- Click Add Condition.
- Enter the following required information. For anonymous users (example):
Field | Description |
---|---|
Code | DC_RULE_FIBER_AVAILABLE_COND |
Context Dimension | DC_RULE_FIBER |
Operator | == |
Value | TRUE |
Default Expression Value | Enable this setting. |
For logged-in users (example):
Field | Description |
---|---|
Code | DC_RULE_MEMBER_STATUS_COND |
Context Dimension | DC_RULE_MEMBER_STATUS |
Operator | == |
Value | Gold |
Default Expression Value | Enable this setting. |
- Click Save.
Perform the following steps to create rule set.
- Click App Launcher.
- Search for Vlocity Product Console and click the link.
- Click + icon next to the Rules Set item in the menu.
- Enter the following required information. For anonymous users (example):
Field | Description |
---|---|
Name | DC_RULE_FIBER_AVAILABLE |
Rule Type | Qualification |
Rule Purpose | Eligibility |
Expression Mode | or |
For logged-in users (example):
Field | Description |
---|---|
Name | DC_RULE_MEMBER_STATUS |
Rule Type | Qualification |
Rule Purpose | Eligibility |
Expression Mode | or |
You can create a single rule set by combining rules for Fiber and MemberStatus by applying expression mode or and executing it using a URI to pass two different context parameters
separated by a comma. For an anonymous user, an example is:
/services/apexrest/vlocity_cmt/v3/catalogs/MOBILE/offers?context={"DC_RULE_MEMBER_STATUS":"Gold","DC_RULE_FIBER_AVAILABLE":"True"}
.
You can pass two or more dimension parameters as part of the API request. You can also create a rule set that calls two different rules that point to two different context dimensions,
in this case, Fiber and Member Status.
When you call the URI, you could pass only one dimension name, Fiber, and not Member Status, andthat will satisfy the rule. If you have two or more context dimensions defined with an
OR condition but you pass just one of them in the request body, then the defined default value is used for the other context dimension.
If you write a URI for Member Status and Fiber Available = True, but there is no value for Member Status, then do not include the parameter value so Digital Commerce does not try to process the null value. Instead, Digital Commerce uses the specified default value for the context dimension value.
If you have defined the default value for DC_RULE_FIBER_AVAILABLE as True, then the request URI skips passing the DC_RULE_FIBER parameter.
- Click Save.
- Click the Children Rules facet.
- Click New Child Rule.
- Add the rule and the sequence.
- Click Save.
- Add more child rules as necessary according to the previous steps.
Perform the following steps to apply the rule set to the product.
- Click App Launcher.
- Search for Vlocity Product Console and click the link.
- Click the Search icon next to the Product item in the menu.
- Search for Fiber Broadband 100 and open it.
- Click Context Rules.
- Click Add Rule Set and search for the DC_RULE_FIBER_AVAILABLE rule.
- Repeat the above steps for the DC_RULE_MEMBER_STATUS rule.
- Click Save.
Before testing the API, you must first run the Populate API Cache job or run theRegenerate Cached API Records job if you are making changes to an existing productcatalog. Perform the following steps to test the API.
- Navigate to Postman.
- Check to Agree to terms of service.
- Click login with Salesforce.
- Select Utilities→REST Explorer in the top menu.
- Leave GET as HTTP selected method.
- Enter the following URL for anonymous users (example).
/services/apexrest/vlocity_cmt/v3/calatogs/FIBER/offers?context={"DC_RULE_FIBER":"true"}
Here accountStatus and AccountSLA have an OR condition with each other, so wecan pass either one of these parameters or both.
/services/apexrest/vlocity_cmt/v3/calatogs/FIBER/offers?context={"AccountStatus":"Active"}
/services/apexrest/vlocity_cmt/v3/calatogs/FIBER/offers?context={"AccountSLA":"Gold"}
/services/apexrest/vlocity_cmt/v3/calatogs/FIBER/offers?context={"AccountStatus":"Active","AccountSLA":"Gold"}
The default value is chosen if you create a rule set with two rules pointing to two different dimension names and only one dimension parameter is passed when invoking the API.
For logged-in users (example):
/services/apexrest/vlocity_cmt/v3/calatogs/FIBER/offers?context={“AccountID”:“xxxxx”}&isloggedin=true
/services/apexrest/vlocity_cmt/v3/calatogs/FIBER/offers?context={“AccountID”:“xxxxx”,"AssetStatus":"Active"}&isloggedin=true
You are specifying the context map in the URL.
- Click Execute.
If fiber technology is available, the API returns a list of products including the Fiber Broadband 100 product and a special reduction in price that is only available for known users who are Gold members.
Similar to the way in which we have created rules to determine the eligibility of products, you can also determine the eligibility of a promotion or qualify for specific price list entries by applying a context eligibility rule. However, applying acontext eligibility rule for a price list entry is only available for known user browsing specific to the getOfferDetails API and the price list entry is returned as part of the results.