> For the complete documentation index, see [llms.txt](https://docs.gaiodataos.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gaiodataos.com/gaio-dataos-spanish/herramientas/tareas/entrega/contenido/documentacion-del-asistente-de-contexto.md).

# Documentación del asistente de contexto

El objeto **`context`** proporciona una interfaz poderosa para acceder a datos y ejecutar acciones dentro del [**Report Static Query Builder**.](/gaio-dataos-spanish/herramientas/tareas/entrega/contenido/generador-de-consultas-estaticas-de-informes.md)

Está disponible globalmente como:

```javascript
window.context
```

Contiene varios componentes clave que permiten interactuar con parámetros, tablas, flujos, formularios y consultas.

### Estructura General

```js
{
  params: {},       // Query parameters
  table: {},        // Available tables with data
  flow: Function,  // Load or open a flow
  form: Function,  // Open a form
  query: {}         // Query builder object
}
```

### Componentes

**params**

El objeto `params` contiene todos los parámetros disponibles para el reporte actual.

```js
// Example
context.params.userId = "12345";
context.params.startDate = "2023-01-01";
```

**table**

El objeto `table` contiene todas las tablas disponibles. Cada tabla es una lista de objetos (filas).

```js
// Example
const firstUser = context.table.users[0];
const totalSales = context.table.sales.reduce((sum, sale) => sum + sale.amount, 0);
```

**flow()**

La función `flow()` permite cargar o abrir otro flujo desde el reporte actual.

**Parámetros:**

```js
context.flow({
  flowId: "flow123",                // Required: ID of the flow to load
  executionType: "loadFlow",        // Required: "loadFlow" or "openFlow"
  reloadCurrentFlow: true,          // Optional: Whether to reload the current page after loading the flow
  reloadCurrentContent: true,       // Optional: Whether to reload the current content after loading the flow
  resetParams: false,               // Optional: Whether to reset params to default after loading the flow
  params: [                         // Optional: Parameters to pass to the flow
    {
      paramName: "userId",
      paramValue: "12345"
    },
    {
      paramName: "view",
      paramValue: "detailed"
    }
  ]
});
```

Opciones de `executionType`

* `openFlow` → Abre el flujo en el panel
* `loadFlow` → Ejecuta el flujo en segundo plano

**form()**

La función `form()` permite abrir un formulario desde el reporte actual.

**Parámetros**

```js
context.form({
  formId: "form123",               // Required: ID of the form to open
  params: [                        // Optional: Parameters to pass to the form
    {
      paramName: "userId",
      paramValue: "12345"
    },
    {
      paramName: "mode",
      paramValue: "edit"
    }
  ]
});
```

**query**

La propiedad `query` permite acceder al constructor de consultas programáticas.

Permite:

* Construir consultas dinámicas
* Aplicar filtros
* Ejecutar agregaciones

{% hint style="info" %}
Para documentación detallada, [consulta la sección específica del Query Builder.](https://docs.gaiodataos.com/gaio-dataos-spanish/~/revisions/xzO0TwfoiEuREgyOO2ZX/herramientas/tareas/entrega/contenido/generador-de-consultas-estaticas-de-informes)
{% endhint %}

## Ejemplos Prácticos

**Navegación Condicional entre Flujos:**

```js
if (context.table.users.length > 0) {
  context.flow({
    flowId: "userDetailsFlow",
    executionType: "flow",
    params: [
      {
        paramName: "userId",
        paramValue: context.table.users[0].id
      }
    ]
  });
} else {
  context.flow({
    flowId: "noUsersFlow",
    executionType: "openFlow"
  });
}
```

**Abrir un Formulario con Datos del Contexto:**

```js
// Open an edit form for the first product in the table
context.form({
  formId: "productEditForm",
  params: [
    {
      paramName: "productId",
      paramValue: context.table.products[0].id
    },
    {
      paramName: "category",
      paramValue: context.params.currentCategory
    }
  ]
});
```

**Cargar un Flujo en Segundo Plano y Refrescar Vista:**

```js
// Update data in the background and then refresh the current view
context.flow({
  flowId: "dataUpdateFlow",
  executionType: "loadFlow",
  reloadCurrentFlow: true,
  reloadCurrentContent: true,
  resetParams: false
});
```

## Buenas Prácticas

1. **Gestión de Parámetros:** Pasa únicamente los parámetros que necesiten cambiar respecto al contexto actual.
2. **Manejo de Errores:** Verifica siempre que los IDs requeridos (`flowId`, `formId`) sean válidos antes de ejecutar las funciones.
3. **Experiencia de Usuario:** Utiliza `reloadCurrentFlow` con precaución, ya que puede interrumpir la experiencia del usuario al refrescar la vista actual.
4. **Rendimiento:** Cuando trabajes con tablas grandes:

* Procesa los datos antes de navegar a otro flujo
* Minimiza la cantidad de datos transferidos


---

# 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://docs.gaiodataos.com/gaio-dataos-spanish/herramientas/tareas/entrega/contenido/documentacion-del-asistente-de-contexto.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.
