---
schema_version: "1"
id: a30dea5f490c75c874085b3ac026831eae683d118848210e6ab8fd8fe31b3f32
title: Creating Context Mappings
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/ind/264-0-0/comms_creating_context_mappings.md
canonical_url: https://help.salesforce.com/s/articleView?id=ind.comms_creating_context_mappings.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 390f830b39780cc937afd7710cb1229963daaa9909fad30a0da341b34af90be4
description: Context mappings allow the rules engine to compare context dimensions to data stored in an sObject, calculated using a function, or entered during design time within a specified context scope. Create context mappings in Vlocity Product Console.
products:
  - Communications
  - Media
  - Energy and Utilities
release: "264"
---
# Creating Context Mappings

Context mappings allow the rules engine to compare context dimensions to data stored in an sObject, calculated using a function, or entered during design time within a specified context scope. Create context mappings in Vlocity Product Console.

You must define context scopes and context dimensions before configuring context mappings.

Context scopes and context dimensions link to context mappings. You can access the context mappings facet when editing a context scope or a context dimension.

**Accessing Context Mappings From a Context Scope**

![Context Mappings follow General Properties in a Context Scope configuration.](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-comms_media_energy_managed-264-0-0-production-enus/ff4079f6-a384-475c-b863-578bbbb0ef9b/resources-product/images/context_mapping_screenshot.jpg)

1. In Vlocity Product Console, in the Rules list, next to Context Dimension or Context Scope, click **Search**.
2. Find the context dimension or the context scope for which to make a context mapping.
3. Click **Edit** to open the context mapping for editing.
4. In the sidebar, click **Context Mappings**.
5. In the **Context Mappings** facet, click **New Context Mapping**.
6. In the **New Context Mapping** dialog box, enter the following information:
    
    <table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
              <colgroup>
                <col>
                <col>
                <col>
              </colgroup>
              <thead class="slds-text-title_caps ">
                <tr class="">
                  <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d23086e128">
                    <p style="margin-bottom:0;">Property</p>
                  </th>
                  <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d23086e134">
                    <p style="margin-bottom:0;">Value</p>
                  </th>
                  <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d23086e140">
                    <p style="margin-bottom:0;">Description</p>
                  </th>
                </tr>
              </thead>
              <tbody>
                <tr class="">
                  <td data-label="Property" class="slds-cell-wrap" style="vertical-align:top;" headers="d23086e128 ">
                    <p style="margin-bottom:0;">
                      <strong class="uicontrol">Context Dimension</strong>
                    </p>
                  </td>

                  <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d23086e134 ">
                    <p style="margin-bottom:0;">Select a context dimension using the<strong class="uicontrol"> Context Dimension Lookup</strong> dialog box.</p>
                  </td>

                  <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d23086e140 ">
                    <p>Specifies the context dimension linked to this context mapping.</p>
                    <p style="margin-bottom:0;">This property only appears when creating a context mapping from a context scope.</p>
                  </td>

                </tr>
                <tr class="">
                  <td data-label="Property" class="slds-cell-wrap" style="vertical-align:top;" headers="d23086e128 ">
                    <p style="margin-bottom:0;">
                      <strong class="uicontrol">Context Scope</strong>
                    </p>
                  </td>

                  <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d23086e134 ">
                    <p style="margin-bottom:0;">Select a context scope using the <strong class="uicontrol">Context Scope Lookup</strong> dialog box.</p>
                  </td>

                  <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d23086e140 ">
                    <p>Specifies the context scope linked to this context mapping.</p>
                    <p style="margin-bottom:0;">This property only appears when creating a context mapping from a context dimension.</p>
                  </td>

                </tr>
                <tr class="">
                  <td data-label="Property" class="slds-cell-wrap" style="vertical-align:top;" headers="d23086e128 ">
                    <p style="margin-bottom:0;">
                      <strong class="uicontrol">Initialization Policy</strong>
                    </p>
                  </td>

                  <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d23086e134 ">
                    <ul>
                      <li>
                        <p>
                          <strong class="uicontrol">Do Not Reinitialize</strong>
                        </p>
                      </li>

                      <li>
                        <p>
                          <strong class="uicontrol">Always Reinitialize</strong>
                        </p>
                      </li>

                    </ul>
                  </td>

                  <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d23086e140 ">
                    <p style="margin-bottom:0;">Specifies how frequently context mapping values are refreshed in the session cache. Salesforce recommends <strong class="uicontrol">Always Reinitialize</strong>. For entity scopes, the rules engine always reinitializes by default, essentially ignoring this selection. However, for session context scopes, the initialization policy is honored.</p>
                  </td>

                </tr>
                <tr class="">
                  <td data-label="Property" class="slds-cell-wrap" style="vertical-align:top;" headers="d23086e128 ">
                    <p style="margin-bottom:0;">
                      <strong class="uicontrol">Initialization Type</strong>
                    </p>
                  </td>

                  <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d23086e134 ">
                    <ul>
                      <li>
                        <p>
                          <strong class="uicontrol">Scope SObject</strong>
                        </p>
                      </li>

                      <li>
                        <p>
                          <strong class="uicontrol">Source Expression</strong>
                        </p>
                      </li>

                      <li>
                        <p>
                          <strong class="uicontrol">Function</strong>
                        </p>
                      </li>

                      <li>
                        <p>
                          <strong class="uicontrol">Type In</strong>
                        </p>
                      </li>

                    </ul>
                  </td>

                  <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d23086e140 ">
                    <p>Specifies where to retrieve the data to use to compare to the rule condition. Supported initialization types are:</p>
                    <ul>
                      <li>
                        <p><strong class="uicontrol">Scope SObject</strong> is reserved for future functionality.</p>
                      </li>

                      <li>
                        <p><strong class="uicontrol">Function</strong> enables you to select a function to perform complex logic. For more information about functions, see <a href="https://help.salesforce.com/s/articleView?id=ind.comms_functions_for_rules.htm&amp;release=264.0.0&amp;type=5" title="In context rules, when you need rules to evaluate complex criteria, you can create a function.">Functions for Rules</a>.</p>
                      </li>

                      <li>
                        <p><strong class="uicontrol">Type In</strong> enables you to enter free-form string values.</p>
                      </li>

                    </ul>
                  </td>

                </tr>
                <tr class="">
                  <td data-label="Property" class="slds-cell-wrap" style="vertical-align:top;" headers="d23086e128 ">
                    <p style="margin-bottom:0;">
                      <strong class="uicontrol">Source Expression</strong>
                    </p>
                  </td>

                  <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d23086e134 ">
                    <p style="margin-bottom:0;">String value</p>
                  </td>

                  <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d23086e140 ">
                    <p style="margin-bottom:0;">Specifies the sObject API name from the context scope. When referring to a field on a custom object using a custom lookup, use <kbd>__r</kbd> instead of <kbd>__c</kbd> as the suffix syntax, for example, ContractId__r.ContractTerm using the Asset context scope. Appears when the <strong class="uicontrol">Initialization Type</strong> is set to <strong class="uicontrol">Source Expression</strong>.</p>
                  </td>

                </tr>
                <tr class="">
                  <td data-label="Property" class="slds-cell-wrap" style="vertical-align:top;" headers="d23086e128 ">
                    <p style="margin-bottom:0;">
                      <strong class="uicontrol">Vlocity Function</strong>
                    </p>
                  </td>

                  <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d23086e134 ">
                    <p style="margin-bottom:0;">Select a function using the <strong class="uicontrol">Function Lookup</strong> dialog box.</p>
                  </td>

                  <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d23086e140 ">
                    <p style="margin-bottom:0;">Appears when the <strong class="uicontrol">Initialization Type</strong> is set to <strong class="uicontrol">Function</strong>.</p>
                  </td>

                </tr>
                <tr class="">
                  <td data-label="Property" class="slds-cell-wrap" style="vertical-align:top;" headers="d23086e128 ">
                    <p style="margin-bottom:0;">
                      <strong class="uicontrol">Type In Value</strong>
                    </p>
                  </td>

                  <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d23086e134 ">
                    <p style="margin-bottom:0;">String value</p>
                  </td>

                  <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d23086e140 ">
                    <p style="margin-bottom:0;">Appears when the <strong class="uicontrol">Initialization Type</strong> is set to <strong class="uicontrol">Type In</strong>.</p>
                  </td>

                </tr>
                <tr class="">
                  <td data-label="Property" class="slds-cell-wrap" style="vertical-align:top;" headers="d23086e128 ">
                    <p style="margin-bottom:0;">
                      <strong class="uicontrol">Sequence</strong>
                    </p>
                  </td>

                  <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d23086e134 ">
                    <p style="margin-bottom:0;">Numeric value</p>
                  </td>

                  <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d23086e140 ">
                    <p style="margin-bottom:0;">Specifies the context mapping sequence. Use a sequence of 10, 20, 30, and so on. to allow for easier sequence changes in the future.</p>
                  </td>

                </tr>
                <tr class="">
                  <td data-label="Property" class="slds-cell-wrap" style="vertical-align:top;" headers="d23086e128 ">
                    <p style="margin-bottom:0;">
                      <strong class="uicontrol">Active</strong>
                    </p>
                  </td>

                  <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d23086e134 ">
                    <p style="margin-bottom:0;">Click to select</p>
                  </td>

                  <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d23086e140 ">
                    <p style="margin-bottom:0;">The rules engine evaluates only active context mappings.</p>
                  </td>

                </tr>
                <tr class="">
                  <td data-label="Property" class="slds-cell-wrap" style="vertical-align:top;" headers="d23086e128 ">
                    <p style="margin-bottom:0;">
                      <strong class="uicontrol">Effective From Date</strong>
                    </p>
                  </td>

                  <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d23086e134 ">
                    <p style="margin-bottom:0;">Select a date</p>
                  </td>

                  <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d23086e140 ">
                    <p style="margin-bottom:0;">The start date of the period during which rules can use the context mapping.</p>
                  </td>

                </tr>
                <tr class="">
                  <td data-label="Property" class="slds-cell-wrap" style="vertical-align:top;" headers="d23086e128 ">
                    <p style="margin-bottom:0;">
                      <strong class="uicontrol">Effective Until Date</strong>
                    </p>
                  </td>

                  <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d23086e134 ">
                    <p style="margin-bottom:0;">Select a date</p>
                  </td>

                  <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d23086e140 ">
                    <p style="margin-bottom:0;">The end date of the period during which rules can use the context mapping.</p>
                  </td>

                </tr>
              </tbody>
            </table>
7. Click **Save**.
    
    After creating a context mapping, the next step is to create a context rule. For more information about creating context rules, [Creating Context Rules](https://help.salesforce.com/s/articleView?id=ind.comms_context_rules.htm&release=264.0.0&type=5 "Context rules determine when a rule set applies in Industries Cart. Context rules are analogous to entity filters in the advanced rules framework.").

## Using Source Expressions

You can create context mappings to specific data stored in sObjects using the source expression property. Using source expressions, you can trace the object hierarchy to access data in objects related by Salesforce lookups.

- Use API names of related sObjects and fields when writing source expressions.
- When referring to a field on a custom object using a custom lookup, use \_\_r instead of \_\_c as the suffix syntax, e.g., ContractId\_\_r.ContractTerm using the Asset context scope.

**Tracing the Object Hierarchy using Source Expressions**

![If the Context Scope is OrderScope and the Source Expression is RecordType.Name, this means that OrderScope is the root scope, Account is the second-level scope, RecordType is the related object, and Name is the field](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-comms_media_energy_managed-264-0-0-production-enus/ff4079f6-a384-475c-b863-578bbbb0ef9b/comms_media_energy_managed/images/image%20\(9\).png)

If the Context Scope is OrderScope and the Source Expression is `RecordType.Name`, the object hierarchy follows:

- OrderScope (Root Scope)
- Account (Second-Level Scope)
- RecordType (Related Object)
- Name (Field)

![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-comms_media_energy_managed-264-0-0-production-enus/ff4079f6-a384-475c-b863-578bbbb0ef9b/images/icon_note.png)

Note

For Initialization Type set as Source Expression, the source expression fields refer to the Context Scope, meaning:

- If the root scope is OrderScope, the API invocation only supports: `Order.Account.RecordType.Name`. It does not support Quote or Opportunity contexts.
- If the root scope is AnyScope, the evaluated expression depends on the invoking API’s runtime context:
    
    Order Context: Order.Account.RecordType.Name
    
    Quote Context: Quote.Account.RecordType.Name
    
    Opportunity Context: Opportunity.Account.RecordType.Name

The final expression depends on the runtime context and the field relationship to the scope object in the source expression

### Using Source Expressions to Map to Virtual Objects

You can also create context mappings to data in virtual objects. Similar to context mappings for regular sObjects, you write source expressions to describe where the rules engine looks for the data. However, when creating mappings to virtual objects, note the following differences.

- Create context mappings to attributes on the virtual object.
- Use the attribute names when writing source expressions.
- Account, Order, Quote and Opportunity are the only sObjects currently supported.
- The ANY attribute is similar to the ANY context scope. For more information, see [Any Context Scope](https://help.salesforce.com/s/articleView?id=ind.comms_any_context_scope.htm&release=264.0.0&type=5 "The any context scope enables you to create context mappings that can be used across all root context scopes. For example, instead of creating separate context mappings to evaluate the status field across orders, quotes, and opportunities, you can use any context scope to evaluate the status for all root entities, including orders and quotes. You can also specify any as the entity for second-level context scopes, enabling you to evaluate information in accounts and contracts across all root entities.").
- For the ANY, Account, Order, Quote and Opportunity attributes, you can refer to fields on those sObjects using the format of \[attribute name\].\[API field name\].
- You can't trace the object hierarchy to access data in related objects.

### Using Source Expressions for Virtual Objects

A Virtual Context Scope includes attributes that either map directly to context mappings or map to fields that then link to context mappings. Use the format:

`[attribute name].[API field name]`

For example:

- Account.RecordType.Name
- Order.Account.Name
- Quote.Account.RecordType.Name

**Using Source Expressions for Virtual Objects**

![A Virtual Context Scope includes attributes, which map directly to context mappings or map to fields that then map to context mappings.](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-comms_media_energy_managed-264-0-0-production-enus/ff4079f6-a384-475c-b863-578bbbb0ef9b/comms_media_energy_managed/images/using_source2.png%20.png)