1c get the row of the tabular section of the document. How to get data from the tabular section of documents

In order to account for money and goods, different tables are widely used in business. Almost every document is a table.

One table lists the items to be shipped from the warehouse. In another table, there are obligations to pay for these goods.

Therefore, in 1C, work with tables occupies a prominent place.

Tables in 1C are also called "tabular sections". Reference books, documents and others have them.

The query, as a result of its execution, returns a table, access to which can be obtained in two different ways.

The first - faster - selection, retrieving rows from it is possible only in order. The second is unloading the query result into a table of values ​​and then random access to it.

// Option 1 - sequential access to query results

// get the table
Selection = Query.Run (). Select ();
// in order, we go through all the rows of the query result
While Fetch.Next () Loop
Report (Sample.Name);
End of Cycle;

// Option 2 - unloading into a table of values
Request = New Request ("SELECT Name FROM Directory.Nomenclature");
// get the table
Table = Query.Run (). Unload ().
// then we can also go through all the lines
For each Row from Table Loop
Report (String.Name);
End of Cycle;
// or arbitrarily access strings
String = Table. Find ("Shovel", "Name");

An important feature is that in the table that is obtained from the query result, all columns will be strongly typed. This means that by requesting the Name field from the Nomenclature reference book, you will receive a column of the type String with an allowable length of no more than N characters.

Table on form (fat client)

The user works with the table when it is placed on the form.

We discussed the basic principles of working with forms in the lesson on and in the lesson on

So, let's place the table on the form. To do this, you can drag the table from the control panel. Similarly, you can select from the menu Form / Insert Control.

Data can be stored in the configuration - then you need to select the existing (previously added) tabular section of the configuration object whose form you are editing.

Click the "..." button in the Data property. In order to see the list of tabular sections, you need to expand the Object branch.

When choosing a tabular section, 1C itself will add columns to the table on the form. The lines entered by the user into such a table will be saved automatically together with the reference / document.

In the same Data property, you can enter an arbitrary name and select the ValuesTable type.

This means that an arbitrary table of values ​​has been selected. It will not automatically add columns, it will not be automatically saved, but you can do whatever you want with it.

By right-clicking on the table you can add a column. In the properties of the column, you can specify its name (for reference in the 1C code), the column heading on the form, the link with the tabular section attribute (the latter - if not an arbitrary table, but the tabular section is selected).

In the properties of the table on the form, you can specify whether the user can add / remove rows. More advanced form - checkbox View Only. These properties are useful for organizing tables for displaying information, but not editing.

To manage the table, you need to display the command bar on the form. Select the menu item Form / Insert Control / Command Panel.

In the properties of the command bar, select the Autocomplete checkbox so that the buttons on the bar appear automatically.

Table on Form (Thin / Managed Client)

On a managed form, these actions look slightly different. If you need to place a tabular section on the form, open the Object branch and drag one of the tabular sections to the left. And that's it!

If you need to place a table of values, add a new attribute of the form and specify the type - table of values ​​in its properties.

To add columns, use the right-click menu on this form attribute, the Add attribute column item.

Then also drag the table to the left.

To make the table have a command bar, in the table properties, select the values ​​in the Usage - Command bar position section.

Export a table to Excel

Any 1C table located on the form can be printed or downloaded to Excel.

To do this, right-click on an empty space in the table and select List.

In a managed (thin) client, similar actions can be performed using the All actions / Display list menu item.

Home For beginner developers Learning to program

How to get data from the tabular section of documents?

For example, consider a situation when you want to get all the items specified in the tabular section. Goods documents Sales of goods and services.

To do this, you can use a request with the following text:

SELECT DIFFERENT Sales of GoodsServices

As a source, we indicate the tabular section of documents - a table Document.Realization of GoodsServices.Products... We declare a field as an output field Nomenclature, which is part of the source table. In addition, since the same heading, of course, could be present more than once in the documents, we apply VARIOUS to get only distinct rows in the query output table.

For example, let's create processing List of Items where the document is selected Sales of goods and services, and clicking on the corresponding button in the message window displays a list of non-repeating items of the nomenclature contained in the tabular section of this document.

In order to restrict the selection of stock items only by items from the tabular section of a specific document, use the parameter Link in the condition in the request ( WHERE...):

SELECT DIFFERENT Implementation of GoodsServicesGoods.Nomenclature AS Nomenclature FROM Document.Realization of GoodsServices.Products AS Implementation of GoodsServicesGoods WHERE Implementation of GoodsServices

Tabular parts exist for many objects in 1C:

  • Reference books
  • The documents
  • Reports and processing
  • Account charts
  • Charts of characteristic types
  • Charts of Calculation Types
  • Business processes and tasks

Tabular sections allow you to store an unlimited amount of structured information belonging to one object.

Let's consider some techniques for working with tabular sections.

How to bypass the tabular section

To traverse the tabular section, you can use a loop For each

For each Row from TabularPart Loop

Report (String. TabularSection Props);

End of Cycle;

At each iteration into a variable Line the next row of the tabular section is transferred. The values ​​of the string attributes can be obtained by the expression String.PropsName.

How to get and traverse the selected rows of a tabular section

To display information from the tabular section of the object, use the form element Table field... To enable the ability to select multiple rows on a table field, set the value Multiple its property Selection mode.

The following code is used to get a list of highlighted lines:

In order to bypass the selected lines, a loop is used For each:

SelectedRows = Form Elements. TabularField Name. SelectedLines;

For each Row of Selected Rows Loop

// contents of the loop

End of Cycle;

How to programmatically select rows of a tabular section (table field) and deselect them

To programmatically deselect the rows of a table field:

Elements of the Form. TabularField Name. Dedicated Rows. Clear ();

To programmatically select all rows of a table field:

For each CurrentRow From TabularPart Loop
Elements of the Form. TabularField Name. Selected Rows. Add (CurrentLine);
End of Cycle;

How to clear the tabular section

TabularPart. Clear ();

How to get the current row of a tabular section

The current line is the time in which the user currently has the cursor. To get it, you need to refer to the control on the form, which is associated with the tabular section.

For normal forms, the code will look like this:

Elements of the Form. TabularField Name. CurrentData;

For managed forms:

Elements. TabularField Name. CurrentData;

How to add a new row to the tabular section

Adding a new line to the end of the tabular section:

NewRow = TabularSection. Add() ;

Adding a new line anywhere in the tabular section (subsequent lines will be shifted):

NewRow = TabularSection. Insert (Index)
// Index is the number of the added line. Line numbering starts at zero.

New line. Props1 = "Value";

How to programmatically fill in the table section row details

If you need to programmatically fill in the attributes of a tabular section row that the user adds, you must use the tabular section event handler At the BeginningEditing.

The procedure created by the handler has three parameters:

  • Element- contains a control TabularField.
  • New line- boolean. Contains value True if a new row of the tabular section is added, and Lie, if the user started editing an already existing line.
  • Copying- boolean. Contains value True if the user copies the string, and Lie in other cases.

Let's look at an example. Let's say we need to fill in the props of the tabular section Account Account, in case a new line is added. When editing an existing line, you do not need to change the accounting account.

Procedure TabularParton StartEditing (Item, NewRow, Copy)

// If the user is editing an existing line, then do nothing
If NOT NewString Then
Return;
EndIf;

// If the line is new, set the accounting account
TextString = Element. CurrentData; // Get the current row of the tabular section
TextString. Account Account = Account Plans. Self-supporting. RequiredAccount;
End of Procedure