> For the complete documentation index, see [llms.txt](https://cortex-docs.paloaltonetworks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cortex-docs.paloaltonetworks.com/xsoar-6-administrator-guide/6.12/configure-cortex-xsoar/customize-and-configure-cortex-xsoar/playbooks/extend-context.md).

# Extend Context

By design, integrations do not write all of the data returned from a command to the context. This prevents large context size and enables you to store only the most relevant information.

The Extend Context feature enables you to save additional data from the raw response of the command. For example, when a command runs to retrieve events from a SIEM, only some of the event fields are written to context, according to the integration design. With Extend Context, you can save additional fields specific to your use case.

Extend Context can also be used when the same command is run multiple times in the same playbook, but the outputs need to be saved to different context keys. For example, you might want to execute the **`!ad-get-user`** command twice, once to retrieve the user's information and again to retrieve the user's manager’s information. By default an integration command writes the data from the same command to the same context key. By using Extend Context, you can write the command’s response to a custom context key of your choice.

You can Extend Context either in a [playbook task](#UUID-14053b46-90ee-413c-3b10-8ddd96552f41) or directly from the [command line](#UUID-ecfb6043-0743-3ab7-fd6b-3126398c681c).

### **Extend Context in a Playbook Task**

You can extend context either in a playbook task, or directly from the command line. Whichever method you use, Cortex XSOAR recommends that you first run your command with the **`raw-response=true`** flag. This helps you identify the information that you want to add to your extended data.

1. Go to the **Advanced** tab of the relevant playbook task.
2. In the **Extend Context** field, enter the name of the field in which you want the information to appear and the value you want to return.

   The following image shows the result of the **`!IPReputation ip=20.8.1.5 raw-response=true`** command, which extends the context of the field name ip with the IP address 20.8.1.5.

   ![playbook-extend-context.png](/files/xeuqnCrnDGmOhabEe7Rs)

   To include more than one field, separate the fields with a double colon. For example: **`attributes=displayName::manager=attributes.manager`**
3. To output only the values for Extend Context and ignore the standard output for the command, select the **Ignore Outputs** checkbox.

   While this will improve performance, only the values that you request in the **Extend Context** field are returned. You cannot use Field Mapping as there is no output to which to map the fields.

### **Extend Context using the Command Line**

You can extend context either in a playbook task, or directly from the command line. Whichever method you use, Cortex XSOAR recommends that you first run your command with the **`raw-response=true`** flag. This will help you identify the information that you want to add to your extended data.

1. Run your command with the extend-context flag **`!`*****`<commandName>`*** ***`<argumentName> <value>`*****`extend-context=contextKey=JsonOutputPath`**.

   For example, to add the user and manager fields to context use the ad-get-user command, as follows:

   **`!ad-get-user username=${user.manager.username} extend-context=manager=attributes.manager::attributes=displayName`**
2. To output only the values that you set as Extend context, run the command with the ignore-output flag=true. **`!ad-get-user username=${user.manager.username} extend-context=manager=attributes.manager::attributes=displayName ignore-output=true`**

**Example**

By default, after adding the IBM Qradar v3 integration instance, offenses pulled from QRadar to Cortex XSOAR return a number of fields, including event count, offense type, description, etc. You can use extended context to show which additional information is available and also use that information to map it to a field.

* Run the command **`!qradar-offenses raw-response="true"`**. From the context data, you see that there are a number of additional fields that are retrieved.
* Identify the fields that you want to add and run your command. For example, to retrieve the number of devices affected by a given offense, as well as the domain in which those devices reside, run the following command: **`!qradar-offenses extend-context=device-count=device_count::domain-id=domain_id`**

The following image shows how to create an extended context key from the CLI in the playground.

![playbook-extend-context-cli.png](/files/IBf7lA11sVZzFXfvz9z1)

### **Use DT syntax to get select keys from a list of dictionaries**

DT syntax is supported within the extend-context value. You can use DT to get select keys of interest from a command that returns a list of dictionaries containing many keys. For example, the findIndicators automation returns a long list of indicator properties, but you may only be interested in saving the value and the indicator\_type to minimize the size of the context data.

**Example**

1. Run the command **`!findIndicators size=2 query="type:IP" raw-response=true`**.

   You will see a list of two dictionaries containing 20+ items.
2. Use the following value for extend-context to save only value and indicator\_type into a context key called FoundIndicators:

   ```programlisting
   !findIndicators size=2 query="type:IP" extend-context=`FoundIndicators=.={"value": val.value, "indicator_type": val.indicator_type}`
   ```
3. Use the following value for extend-context to save only the incident name, status, and id to a key called FoundIncidents:

   ```programlisting
   !SearchIncidentsV2 id=<ANY_INCIDENT_ID> extend-context=`FoundIncidents=Contents.data={"name": val.name, "status": val.status, "id": val.id}` ignore-outputs=true
   ```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://cortex-docs.paloaltonetworks.com/xsoar-6-administrator-guide/6.12/configure-cortex-xsoar/customize-and-configure-cortex-xsoar/playbooks/extend-context.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
