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

1c get a row of the tabular part of the document.  How to get data from the tabular part of documents?  How to get the current row of a tabular section
1c get a row of the tabular part of the document. How to get data from the tabular part of documents? How to get the current row of a tabular section
Home For Beginner Developers Learn to Program

How to get data from the tabular part of documents?

For example, consider a situation where you want to get all stock items specified in the tabular section Goods documents Realization of Goods and Services.

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

CHOOSE DIFFERENT Realization of Goods of Services Goods.Nomenclature AS Nomenclature FROM Document. Realization of Goods of Services. Goods AS Realization of Goods of Services Goods

As a source, we indicate the tabular part of the documents - the table Document.Sale of GoodsServices.Goods. Declare a field as an output field Nomenclature A that is part of the source table. In addition, since the same commodity item, 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 a processing Product List where the document is selected Realization 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 nomenclature only to the nomenclature from the tabular section of a specific document, we use the parameter Link in the condition in the request ( WHERE...):

SELECT DIFFERENT Realization of Goods of Services Goods. Nomenclature AS Nomenclature FROM Document. Realization of Goods of Services. Goods AS Realization of Goods of Services Goods WHERE Realization of Goods of Services Goods. Link = & Link

Tabular parts exist for many objects in 1C:

  • Reference books
  • Documentation
  • Reports and processing
  • Charts of accounts
  • Plans of types of characteristics
  • 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 methods of working with tabular parts.

How to bypass the tabular part

You can use a loop to traverse the tabular part For each

For each Row from TabularPart Loop

Report(String.TablePartAttribute) ;

EndCycle ;

At each iteration into a variable Line the next line of the tabular part is transferred. String attribute values ​​can be obtained by the expression String.AttributeName.

How to get and bypass the selected rows of the tabular section

The form element is used to display information from the tabular part of the object. table field. To enable the ability to select multiple rows in a table field, you need to set the value Multiple at its property Selection Mode.

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

Loop is used to iterate over selected lines For each:

SelectedLines = FormElements. TableFieldName. Selected Lines;

For each Row from Selected Rows Loop

//loop content

EndCycle ;

How to programmatically select the rows of the tabular part (table field) and remove the selection

To programmatically deselect rows in a table field:

ElementsForm. TableFieldName. SelectedStrings. Clear() ;

To programmatically select all rows in a table field:

For each CurrentRow From TabularPart Loop
ElementsForm. TableFieldName. Selected Lines. Add(CurrentRow) ;
EndCycle ;

How to clear the spreadsheet

TabularPart. Clear() ;

How to get the current row of a tabular section

The current line is the period in which the user has this moment the cursor is located. To get it, you need to refer to the control on the form, which is associated with the tabular part.

For regular forms the code will look like this:

ElementsForm. TableFieldName. CurrentData;

For managed forms:

Elements. TableFieldName. CurrentData;

How to add a new row to a spreadsheet

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

NewRow = TablePart. Add() ;

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

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

New line. Attribute1 = "Value" ;

How to programmatically fill in the details of a table row

If you need to programmatically fill in the details of the row of the tabular section that the user adds, you must use the event handler of the tabular section AtStartEditing.

The procedure created by the handler has three parameters:

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

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

Procedure TabularPartAt EditingStart(Element, NewRow, Copy)

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

//If the string is new, set the account
TextString = Element. CurrentData; //Got current line tabular part
TekString. AccountAccount = Charts of Accounts. Self-supporting. Desired Account;
EndProcedure

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

One table lists the goods to be shipped from the warehouse. In another table - the obligation to pay for these goods.

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

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

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

The first - faster - selection, getting 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 table
Selection = Query.Execute().Select();
// bypass all rows of the query result in order
While Selection.Next() Loop
Report(Selection.Name);
EndCycle;

//Option 2 - uploading to the table of values
Query = New Query("SELECT Name FROM Directory.Nomenclature");
// get table
Table = Query.Execute().Upload().
// then we can also bypass all lines
For each Row from Table Loop
Report(String.Name);
EndCycle;
//or arbitrarily access strings
String = Table.Find("Shovel", "Name");

An important feature is that in the table that is obtained from the result of the query, all columns will be strongly typed. This means that by requesting the Name field from the Nomenclature lookup, 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 control panel. Similarly, you can select the Form/Insert control from the menu.

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

Click the "..." button in the Data property. To see the list tabular parts, you need to open the Object branch.

When choosing a tabular part, 1C itself will add columns to the table on the form. The strings entered by the user into such a table will be automatically saved along with the directory/document.

In the same Data property, you can enter an arbitrary name and select the ValueTable 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.

Clicking right click 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 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 ViewOnly checkbox. These properties are useful for organizing tables intended for displaying information, but not for editing.

To manage the table, you need to display the command panel 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 toolbar appear automatically.

Table on form (thin/managed client)

On managed form these actions look a little different. If you need to place a tabular section on the form, expand 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 form attribute and specify the type in its properties - a table of values.

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

Then also drag the table to the left.

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

Exporting 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 Show List.

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