Generate a Document with Tabular Data
If you are developing integrations for Bitrix24 using AI tools (Codex, Claude Code, Cursor), connect the MCP server so that the assistant can utilize the official REST documentation.
Tabular data for template placeholders is passed to the method documentgenerator.document.add as an array of strings in values. In fields, you need to specify the table provider so that the generator processes the array as repeating rows.
When to Use
- When you need to fill a single table with rows of the same structure
- Each row of the table contains a simple set of values, such as name, price, and image
- When you need to display the row number within the table
What to Pass in the Request
- In
fields['Table']['PROVIDER'], specifyBitrix\\DocumentGenerator\\DataProvider\\ArrayDataProviderso that the generator processesvalues['Table']as a list of table rows - In
fields['Table']['OPTIONS'], specify:ITEM_NAME— the internal name of the array elementITEM_PROVIDER—Bitrix\\DocumentGenerator\\DataProvider\\HashDataProvider
- In
values['Table'], pass the list of table rows - For table placeholders, such as
TableItemNameandTableItemPrice, provide the data access chain:Table.Item.Name,Table.Item.Price - For images in the table, specify
TYPE = IMAGEinfields - For the row number, you can use
Table.INDEX
Example
$data = [
'templateId' => 203,
'providerClassName' => 'Bitrix\\DocumentGenerator\\DataProvider\\Rest',
'value' => 'ORDER_1024',
'values' => [
'Table' => [
[
'Name' => 'Item name 1',
'Price' => '$111.23',
'Image' => 'https://myrestapp.example/upload/product-1.png'
],
[
'Name' => 'Item name 2',
'Price' => '$222.34',
'Image' => 'https://myrestapp.example/upload/product-2.png'
],
],
'TableItemName' => 'Table.Item.Name',
'TableItemImage' => 'Table.Item.Image',
'TableItemPrice' => 'Table.Item.Price',
'TableIndex' => 'Table.INDEX',
],
'fields' => [
'Table' => [
'PROVIDER' => 'Bitrix\\DocumentGenerator\\DataProvider\\ArrayDataProvider',
'OPTIONS' => [
'ITEM_NAME' => 'Item',
'ITEM_PROVIDER' => 'Bitrix\\DocumentGenerator\\DataProvider\\HashDataProvider',
],
],
'TableItemImage' => ['TYPE' => 'IMAGE'],
],
];
$url = $webHookUrl.'documentgenerator.document.add/';
How It Works
In the example, it is assumed that the template contains a table with fields {TableItemName}, {TableItemImage}, {TableItemPrice}.
- The
Tablefield is used as a container for the array of rows. This placeholder may not exist in the template, but it is necessary to pass the array of values for the table. - By
ITEM_NAME = Item, the provider reads each row element as anItemobject. - By
ITEM_PROVIDER = HashDataProvider, the elements are read as a simple hash. - Fields like
TableItem...reference values through the chainTable.Item.<Key>, where<Key>is the key of the internal associative array, such asName,Price, orImage.
Table.INDEX returns the current row number, starting from 1.
If a regular string is specified as the value of a field, it will be inserted into the table as is in all rows.
Continue Learning
- Generate a Document with Text
- Generate a Document with Date and Name Modifiers
- Generate a Document with Complex Tables
- Generate a Document with Images and Stamps
- Typical use-cases and scenarios of the document generator: case overview
Copied