# Context

{% hint style="success" %}
This is the official documentation of Forest Admin Cloud.
{% endhint %}

The `context` of an action contains all the context data when the action is executed in Forest Admin.

***

{% hint style="info" %}
To make the code easier to read, all the code snippets below should be wrapped in the following code. Ensure you update the collection and action names as needed.

```typescript
import type { Agent } from '@forestadmin/forest-cloud';
import { Schema } from '../typings';

export default function customizeAgent(agent: Agent<Schema>) {
  agent.customizeCollection('user', (collection) => {
    collection.addAction('Ban user', {
      scope: 'Single',
      // Insert the code snippet here.
    });
  });
}
```

{% endhint %}

### Getting the selected record(s)

To get the selected record(s) on which the action is executed, use the `getRecord()` or `getRecords()` methods from the context.

Example:

{% tabs %}
{% tab title="Single scope" %}

```typescript
execute: async (context) => {
  const { id, email } = await context.getRecord(['id', 'email']);
},
```

{% endtab %}

{% tab title="Bulk or Global scopes" %}

```typescript
execute: async (context) => {
  const { id, email } = await context.getRecords(['id', 'email']);
},
```

{% endtab %}
{% endtabs %}

### Getting the selected record id(s)

Additionally, you can retrieve just the id(s) by using `getRecordId()` or `getRecordIds()`

Example:

{% tabs %}
{% tab title="Single scope" %}

```typescript
execute: async (context) => {
  const id = await context.getRecordId();
},
```

{% endtab %}

{% tab title="Bulk or Global scopes" %}

```typescript
execute: async (context) => {
  const ids = await context.getRecordIds();
},
```

{% endtab %}
{% endtabs %}

### Getting the collection

To access the collection associated with an action, use the `collection` attribute. To see the capabilities of what `collection` provides, please see the following section: [Query interface and Native Queries](https://docs.forestadmin.com/developer-guide-agents-nodejs/data-sources/getting-started/queries)

Example:

```typescript
execute: async (context) => {
  await context.collection.update(context.filter, { isBanned: true });
},
```


---

# Agent Instructions: 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:

```
GET https://docs.forestadmin.com/cloud/code-customization/actions/context.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
