1c get the name of the table section. How to get data from the tabular part of documents? How to get the current row of a table section

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

One table lists the goods to be shipped from the warehouse. Another table shows the obligations to pay for these goods.

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

Tables in 1C are also called “tabular parts”. Directories, documents and others have them.

The query, when executed, returns a table that can be accessed in two different ways.

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

//Option 1 – sequential access to query results

//get the table
Select = Query.Run().Select();
// we go through all the lines of the query result in order
While Select.Next() Loop
Report(Selection.Name);
EndCycle;

//Option 2 – uploading to a table of values
Request = New Request("SELECT Name FROM Directory.Nomenclature");
//get the table
Table = Query.Run().Unload().
//further we can also iterate through all the lines
For each Row from Table Cycle
Report(String.Name);
EndCycle;
//or arbitrarily access strings
Row = Table.Find("Shovel", "Name");

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

Table on the form (thick 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 Controls panel. Similarly, you can select Form/Insert Control from the menu.

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

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

When you select the tabular part, 1C itself will add columns to the table on the form. Rows entered by the user into such a table will be saved automatically along with the reference book/document.

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

This means that an arbitrary table of values ​​has been selected. It will not automatically add columns, nor will it 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 a column, you can specify its name (for reference in 1C code), the column heading on the form, the connection with the attribute of the tabular part (the latter - if not an arbitrary table is selected, but a tabular part).

In the table properties on the form, you can specify whether the user can add/delete rows. A more advanced form is the View Only checkbox. These properties are convenient to use for organizing tables intended for displaying information, but not editing.

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

In the command bar properties, select the Autofill checkbox so that the buttons on the panel appear automatically.

Table on form (thin/managed client)

On a managed form, these actions look a little different. If you need to place a tabular part on the form, expand the Object branch and drag one of the tabular parts to the left. That's all!

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

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

Then also drag the table to the left.

In order for a table to have a command bar, in the table properties, select the values ​​in the Usage – Command bar position section.

Uploading a table to Excel

Any 1C table located on the form can be printed or uploaded 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 menu item All actions/Display list.

home For beginner developers Learn to program

How to get data from the tabular part of documents?

For example, consider a situation where you need to get all the item 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 VARIOUS Sales of Goods and Services Goods. Nomenclature AS Nomenclature FROM Document. Sales of Goods and Services. Goods AS Sales of Goods and Services Goods

As a source we indicate the tabular part of the documents - table Document. Sales of Goods and Services. Goods. We declare the output field to be the field Nomenclature, which is part of the source table. In addition, since the same product item, naturally, could be present more than once in the documents, we use VARIOUS to get only the distinct rows in the query output table.

For example, let's create a processing Product List, where the document is selected Sales of Goods and Services, and by clicking on the corresponding button, a list of non-repeating items of the nomenclature contained in the tabular part of this document is displayed in the message window.

In order to limit the selection of items only to items from the tabular part of a specific document, we use the parameter Link in the condition in the request ( WHERE...):

SELECT VARIOUS Sales of Goods and Services Goods. Nomenclature AS Nomenclature FROM Document. Sales of Goods and Services. Goods HOW Sales of Goods and Services Goods WHERE Sales of Goods and Services Goods. Link = &Link

Tabular parts exist for many objects in 1C:

  • Directories
  • Documentation
  • Reports and processing
  • Charts of accounts
  • Characteristic type plans
  • Calculation type plans
  • Business processes and tasks

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

Let's look at some techniques for working with tabular parts.

How to bypass the tabular part

To traverse the table part, you can use a loop For each

For each Row from the Tabular Part of the Cycle

Report(String. TabularPart attribute) ;

EndCycle ;

At each iteration into the variable Line the next row of the tabular section is transmitted. The values ​​of the row details can be obtained by the expression Line.AttributeName.

How to get and bypass selected rows of the tabular part

To display information from the tabular part of the object, use a form element Table field. To enable the ability to select multiple rows in a table field, you need to set the value Multiple at his property Selection mode.

To get a list of selected lines, use the following code:

A loop is used to iterate through the selected lines. For each:

SelectedRows = FormElements. TableFieldName. SelectedRows;

For each Row from Selected Rows Loop

//loop contents

EndCycle ;

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

To programmatically deselect rows of a table field:

Form Elements. TableFieldName. SelectedRows. Clear() ;

To programmatically select all rows of a table field:

For each CurrentRow From TabularPart Loop
Form Elements. TableFieldName. SelectedLines. Add(CurrentRow) ;
EndCycle ;

How to clear the table part

TabularPart. Clear() ;

How to get the current row of a table section

The current line is the timeline in which the user currently has the cursor. To get it, you need to access the control element on the form that is associated with the tabular part.

For regular forms the code will look like this:

Form Elements. TableFieldName. CurrentData;

For managed forms:

Elements. TableFieldName. CurrentData;

How to add a new row to a table section

Adding a new line to the end of the table part:

NewRow = TablePart. Add() ;

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

NewRow = TablePart. Insert(Index)
//Index - number of the added line. Line numbering starts from zero.

New line. Props1 = "Value" ;

How to programmatically fill in the details of a table row

If you need to programmatically fill in the details of a table section row that is added by the user, you must use the table section event handler When StartingEditing.

The procedure created by the handler has three parameters:

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

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

Procedure TabularPartAtStartEditing(Element, NewRow, Copy)

//If the user edits an existing line, then we do nothing
If NOT NewRow Then
Return;
EndIf ;

//If the line is new, set the accounting account
TechString = Item. CurrentData; //Get the current row of the tabular part
TechString. Accounting = Charts of Accounts. Self-supporting. RequiredAccount;
End of Procedure