How to set up smartphones and PCs. Informational portal
  • home
  • Windows phone
  • 1c work with the tabular part of the document. How to programmatically fill in the details of a table row

1c work with the tabular part of the document. How to programmatically fill in the details of a table row

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 everybody

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 everybody:

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 TablePart 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 currently has the cursor. 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 would 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 a new row of the tabular section is added, 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; //Received the current row of the tabular section
TekString. AccountAccount = Charts of Accounts. Self-supporting. Desired Account;
EndProcedure

Within the framework of this article, we will write the processing of filling in the tabular part in 1C 8.3 for a typical 1C: ERP 2.1 configuration. Let's assume that the goal of the task is to set a manual discount of 5% for all stock items of this document. An example from the article can be downloaded by or other similar processing by .

This instruction is for managed forms (8.2 and 8.3). For regular forms (8.1, 8.2) you can use .

Create and save a new treatment to your computer. First you need to perform some registration steps.

Open the object module and write the code below (it can also be taken from the processing given above). In general, the structure will not change depending on the situation. Only some settings parameters are edited, as well as, if necessary, variable names.

Within the framework of this article, we will not dwell on the registration of external processing and printing forms in 1C. All this information is in our other articles.

Filling in the tabular part of the document

Let's create a new processing form.

Now we need to add a new command on the created form. It is assumed that it will automatically change the data in the tabular part of both one and several documents (their list forms) at the same time, writing them down later.

As part of our example, the already existing tabular part "Products" will be processed. A manual discount of 5% will be set for each line. Also, we will calculate the amount of this discount, equal to the sum of goods in the line, multiplied by 0.05.

&OnServer Procedure ExecuteCommand(Command, Destination Objects) For each Customer Order from Destination Objects Loop Customer Order Object = Customer Order. GetObject() ; For each TK Line from CustomerOrderObject. Goods Cycle String TZ. PercentManualDiscount = 5 ; String TZ. Amount ofManualDiscount = String TK. Amount * 0 . 05; EndCycle ; OrderCustomerObject. Write() ; EndCycle ; EndProcedure

Registration of external processing

Run 1C in the "Enterprise" mode and open the "Additional reports and processing" directory. Find it through the "All functions" menu.

Create a new element in the directory that opens and use the button of the same name to load your processing from the file. Let's place it simultaneously both on the list form and on the form of the document card itself.

Now in the form of the list of documents "Customer Order" the button "Filling ..." will appear, which will allow you to change the manual discounts of goods for several documents at once.

Also, this button will be available in the card of the document itself.

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, which 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. In order to see the list of tabular parts, you need to expand 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.

By right clicking on the table you can add a column. In the column properties, 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, but a tabular part is selected).

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 a 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 all!

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.

Top Related Articles