---
schema_version: "1"
id: c0efe843f35b7234318fb719f6cbe15f4362cd3815fd0dc325fefe7de39fbe96
title: Set Up Context Variables for Service Assistant
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/service/264-0-0/sp_setup_cv.md
canonical_url: https://help.salesforce.com/s/articleView?id=service.sp_setup_cv.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 7564848db33118ff2370a0c80980ff6d9eb3b65447c5fb835ae93a3e72b498ba
description: Give Service Assistant the ID of the active record so that it can complete actions such as closing a case or updating a record without the service rep entering the ID manually.
products:
  - Service Cloud
  - Service Intelligence
release: "264"
---
# Set Up Context Variables for Service Assistant

Give Service Assistant the ID of the active record so that it can complete actions such as closing a case or updating a record without the service rep entering the ID manually.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition">
        <colgroup>
          <col style="width:50%">
          <col style="width:50%">
        </colgroup>
        <tbody>
          <tr class="">
            <td class="slds-cell-wrap" colspan="2" style="vertical-align:top;"><a href="https://help.salesforce.com/s/articleView?id=service.messaging_editions.htm&amp;type=5&amp;language=en_US" target="_blank">View supported editions.</a></td>

          </tr>
          <tr class="">
            <td class="slds-cell-wrap" style="vertical-align:top;">
              <span style="vertical-align:text-bottom;display:inline-block;"><img style="margin-bottom:0;" src="https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-service-support_intelligence-264-0-0-production-enus/dcd06a7b-b5ab-448b-a767-4e2e90481508/resources-global/_corporate/images/checkmark.png" alt="Checkmark"></span> This article applies to:
            </td>

            <td class="slds-cell-wrap" style="vertical-align:top;">Service Assistant for Case, Messaging, and Voice</td>

          </tr>
        </tbody>
      </table> <table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small permission">
        <colgroup>
          <col style="width:50%">
          <col style="width:50%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="colgroup" class="slds-cell-wrap" colspan="2" style="text-align:center;vertical-align:top;" id="d76797e79">User Permissions Needed</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d76797e79 ">To set up context variables in Service Assistant:</td>

            <td class="slds-cell-wrap" style="vertical-align:top;" headers="d76797e79 ">
              <p>Service Planner Builder permission set</p>
              <p>AND</p>
              <p style="margin-bottom:0;">System Admin OR Customize
                Application</p>
            </td>

          </tr>
        </tbody>
      </table>

![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-service-support_intelligence-264-0-0-production-enus/dcd06a7b-b5ab-448b-a767-4e2e90481508/images/icon_note.png)

Note Reference guidance for context variables in Service Assistant is provided in [Grounding with Context Variables (Optional)](https://help.salesforce.com/s/articleView?id=service.sp_cv.htm&release=264.0.0&type=5 "Learn how Service Assistant uses context variables to pass the active record ID into plan steps and actions, and review the configuration guidelines.").

First, create the currentRecordId context variable. Then assign it as an input to each action that needs the record ID, including flows, prompt template, and Apex actions.

We include steps for adding currentRecordId to a flow because the setup is specific to flow-based actions. For other action types, such as prompt template and Apex actions, assign currentRecordId to the action's input.

## Set Up the Context Variable

Create the currentRecordId context variable and add a description so that Service Assistant knows when to use it.

1. In Agentforce Builder, deactivate your agent.
2. Select the **Context** tab and click **New Variable**.
3. Enter these values.
    1. Name: currentRecordId
    2. API Name: currentRecordId
    3. Data Type: Text
    4. Description: The ID of the record on the user's screen. It might not relate to the user's input. Use this only if the user input mentions "this," "current," or "the record." If in doubt, don't use it.
4. Select both **Allow value to be set by API** and **Allow LLM to use value**.
5. Click **Save**.
6. Reactivate your agent.

## Assign the Context Variable to Flows

If you use a flow-based action, add currentRecordId as an input variable and update the Get Records element to filter by it.

1. In Flow Builder, open your flow.
2. Click **New Resource** and select **Variable**.
3. Enter these values.
    1. API Name: currentRecordId
    2. Data Type: **Text**
    3. Select **Available for Input**.
4. Click **Done**.
5. Click **New Resource** again and select **Variable**.
6. Enter these values.
    1. API Name: a name for your record variable, such as caseRecord or messagingRecord
    2. Data Type: **Record**
    3. Object: the object that your flow retrieves, Case or Messaging Session
7. Click **Done**.
8. Open the **Get Records** element.
9. Under **Filter Records**, set these values.
    1. Field: Case ID or Messaging Session ID
    2. Operator: **Equals**
    3. Value: currentRecordId
10. Under **How to Store Record Data**, select **Choose fields and assign variables (advanced)**.
11. Under **Where to Store Field Values**, select **Together in a record variable**.
12. Under **Select Variable to Store Record**, select your record variable, caseRecord or messagingRecord.
13. Save your flow.

Return to Agentforce Builder and assign the context variable to your actions.

## Assign the Context Variable to an Action Input

Assign currentRecordId to an action input so that Service Assistant automatically passes the current record ID into the action at session start.

1. In Agentforce Builder, open an action.
2. From the input field, select **Assign a Variable** and choose **currentRecordId**.
3. Make sure that **Available for Input** is selected on the input field.
4. Save and reactivate your agent.
5. Start a new session. Context variables are populated at session start and don't update mid-session.

Keep in mind that the behavior of currentRecordId depends on whether **Require User Confirmation** is selected on the action.

- If **Require User Confirmation** isn't selected, Service Assistant automatically passes the record ID into the action without prompting the rep.
- If **Require User Confirmation** is selected, Service Assistant pauses and displays a confirmation prompt to the rep with the record ID prefilled.