1c 8 external processing of the tabular part. Document connection

1. Statement of the problem

In this article, we will consider the process of writing the simplest external processing of filling a tabular part in 1C 8 for configurations using a normal application. For example, let's take the following task: “In the configuration 1C: Accounting 2.0 create an external processing of filling the tabular section Goods document, the data to be filled in is taken from the tabular section Goods document Receipt of goods and services". Thus, we need to fill in the goods of sale based on the goods of receipt, such a task is quite common in the real practice of a 1C programmer.

2. Creating external processing

Let's go to 1C 8 in mode Configurator. Using the menu File -> New or pictograms new document create a new external processing.

In field Name we indicate: “The simplest Filling in the Tabular Part” and save the external processing to the hard disk using the menu File -> Save or icon Save or keyboard shortcut ctrl+s.

Selecting a branch Requisites in the processing metadata tree and clicking the button Add(button with a green plus) create a new external processing attribute - DocumentReceipts, choose the type for it DocumentReference.Receipt of GoodsServices, we need this attribute to select a document Receipt of goods and services, on the basis of which the implementation will be filled.

To select a receipt document, we need a separate form. Selecting a branch Forms and using the same button - Add Let's create an external processing form. The form designer window will open, you don’t need to make any changes on the first page of the designer, so just click the button Further.

On the second page of the constructor, we need to select the props DocumentReceipts(in order for it to appear on the created form) and press the button Ready.

After that, the created form will open, we need the user to select the receipt document on it and close it. So when the button is pressed Run the form should just close. In order to implement this, select the button Run, right click on it and select Properties. In the properties of the button, in the line Action select an action close. This completes the work with the form, close it.

3. Programming

Let's start programming the processing of filling the tabular part. Let's go to Object module external processing (on the bottom processing panel, the button Actions -> Open object module).

In it we need to create an export procedure Initialize.

Procedure Initialize Export EndProcedure

note that procedure Initialize, as well as all its parameters, are mandatory for external processing of filling in the tabular section, if you don't create it or if you don't provide all the parameters, your processing simply won't work.

Now let's start writing the code. First of all, let's create a variable for the tabular part of the document Sale of goods and services which we will fill in.

TablePart = Object[TablePartName];

When executing the procedure in the parameter An object will contain the document object that we fill in, and in the parameter TablePartName a string with the name of the tabular part that we are filling. Thus, this line of code gets the tabular part of the filled document by its name.

We need the user to select a document Receipt of goods and services, so let's write the code for opening the document selection form. First, we get this form into a variable using the external processing method GetForm(<Форма>, <Владелец>, <КлючУникальности>) . It is enough for us to fill in only the first parameter of this method, passing there a string with the name of our form.

IncomingSelectionForm = GetForm("Form" );

Now let's open the resulting form using modal opening (while the form is open, all other 1C windows are unavailable), because with this method of opening, our further code in the procedure Initialize will not be executed until the user closes the form.

AdmissionSelectionForm.OpenModally();

After the user closes the form, we need to check if the attribute is filled in DocumentReceipts(in case no receipt document has been selected). If after checking DocumentReceipts is empty, then further processing does not make sense, and it should be interrupted.

If NOT ValueFilled(ReceiptDocument) Then Report(); Return ; EndIf ;

To check the fullness of the attribute, the global context function is used here ValueFilled(<Значение>) , it checks if the value passed in the parameter is different from the default value of the same type. Procedure To report displays the specified text in the 1C 8 message box. Keyword Return interrupts the execution of the procedure.

Let's start writing a query that will select the data of the tabular part Goods document Receipt of goods and services. Let's create a new request:

Request = New Request;

Request.SetParameter( "Receipt Document",Receipt Document);

Let's write the text of the request, we will do it with the help of Request constructor. Writing the request text manually is not recommended, it is not efficient and takes a lot of time. Let's start with a line:

Request.Text = "" ;

Put the cursor between the quote characters, press the right mouse button and select the item Request constructor.... After that, you will be prompted to create a new request, click the “OK” button. A constructor window will open, in its left part all available database tables are located, we need a document Incoming Goods Services. Find it and open it with the “+” symbol, select the tabular part Goods and drag it to the second part of the designer screen, which is called tables(You can also move the desired table using the “>” button).

Now we will expand the table we have chosen by “+” ( Incoming Goods Services Goods) and drag the fields necessary for our filling in the tab-part to the third part of the constructor screen, which is called - fields. We will not select all available fields, we will limit ourselves to the following set: Nomenclature, Quantity, Price, Amount, VAT Rate, VAT Amount.

Since we need the data of only one receipt document (which we selected before starting filling), then on the “Conditions” tab, we will impose a condition on the document link using the parameter we passed.

The creation of the query text in the constructor is now complete, click the “OK” button. As a result, we have the following request text:

Query.Text = "SELECT |FROM |WHERE ;

The created request only needs to be executed and unloaded into a variable:

Result = Request.Execute().Upload();

In a variable Result a table of values ​​is stored with the rows of the tabular part Goods document of our choice Receipt of goods and services. Now you can start filling in the spreadsheet. Goods our implementation. But before filling in the data, you should clear it, in case there are already some lines there.

TablePart.Clear();

With a cycle For each let's go around the table of values ​​with the results of the query.

For Each Result Element Of Result Loop End Of Loop ;

In this cycle, we will create and fill in the lines of the tabular part of the document Sale of goods and services. We can create a new line using a variable TabularPart, through which you can perform any action with it.

NewStringPT = TabularPart.Add();

Fill in the created line tab. parts of the data from the query result string using the procedure global contextFillPropertyValues(<Приемник>, <Источник>) .

FillPropertyValues(NewStringPT,ResultElement);

But the data we filled in is not enough, in order for the document to be carried out, it is necessary to fill in more inventory accounting accounts. To do this, we use the export

procedure Fill InvoicesAccountingInRowTabParts from document object module Sale of goods and services. Let's call it with the parameter An object(it should be noted

that we can only call export procedures from the document object module).

Object.FillAccountsAccountingInTabPartRow(NewPTRow, TabularPartName, True);

This completes the programming of filling the tabular part for 1C 8 completed. processing can be used. Full text of the procedure Initialize, looks like that:

Procedure Initialize (Object, TabularPartName = Undefined, Object TableField = Undefined) Export TablePart = Object[TablePartName]; IncomingSelectionForm = GetForm("Form" ); AdmissionSelectionForm.OpenModally(); If NOT ValueFilled(Incoming Document) Then Report ( "No receipt document selected"); Return ; EndIf ; Request = New Request; Request.SetParameter( "Receipt Document",Receipt Document); Query.Text = "SELECT | Receipt of Goods, Services, Goods. Nomenclature, | Receipt of Goods, Services, Goods. Quantity, | Receipt of Goods, Services, Goods. VAT Rate, | Receipt of Goods, Services, Goods. Amount, | Receipt of Goods, Services, Goods. Amount of VAT, | Receipt of Goods, Services, Goods. Price| FROM | Document.Receipt of GoodsServices.Goods AS Receipt of GoodsServicesGoods|WHERE | GoodsReceiptServicesGoods.Reference = &ReceiptDocument"; Result = Request.Execute().Upload(); TablePart.Clear(); For Each Result Element From Result Loop NewRowPT = TabularPart.Add(); FillPropertyValues(NewStringPT,ResultElement); Object.FillAccountsAccountingInTabPartRow(NewPTRow, TabularPartName, True); EndCycle ; EndProcedure

The next part of the article will tell you how to debug the processing of filling in the tabular part and how to connect it to the document.

4. Debugging

Quite often, you need to debug the code you write. In order to debug the processing of filling the tabular part in 1C 8 create her props ReferenceToObject type DocumentReference.Realization of GoodsServices

We need it in order to select an implementation document during debugging, which we will fill out. Next, you need to create a form for debugging and place the created props there. ReferenceToObject, the process of creating a debugging form does not differ from creating a receipt document selection form, so we will not dwell on it in detail.

After the form is created, go to its module. There we will find an automatically created procedure ButtonExecutePushing. This procedure executes when the button is pressed. Run. Let's call a procedure from it Initialize, which is located in the processing module, we will pass the document object to the parameters Sale of goods and services(which we will get from props ReferenceToObject) and a line with the name of the tabular part to be filled in (in our case Goods).

Procedure ButtonExecuteClick(Button) Initialize(ReferenceToObject.GetObject(), "Goods" ); EndProcedure

Now you need to make the created form the main processing form. To do this, select it in the "Processing Form" field.

Now you can set a breakpoint at the right place in the procedure Initialize or procedures ButtonExecutePushing debug forms, and start processing the filling of the tabular section in debug mode 1C:Enterprise.

5. Connecting to a document

After filling processing is written and debugged, it should be connected to the document from which it will be executed. To do this, go to 1C 8 in mode Company, go to the menu Service -> Additional reports and processing -> Additional external processing of tabular parts and add a new directory element. With button Replace external processing file Let's add the file of the processing of filling the tabular section created by us.

Fill in the processing affiliation by using the button Selection choose a document Sale of goods and services

And we indicate that the filling is intended for the tabular part Goods.

We press the button OK and that's it, filling processing will be available in the menu Fill tabular part Goods document Sale of goods and services. You can download the processing used for this example by .

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 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 itself, equal to the sum of goods in the line, multiplied by 0.05.

&At Server Procedure Execute Command(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 perform some actions with the rows of the tabular part, it is not necessary to change the configuration. The 1C 8.2 platform has a mechanism that allows you to work with the tabular part using external processing. To do this, processing must be formalized in an appropriate way and placed in the directory of external processing. After that, a button will appear in the desired document, which will perform the action prescribed in the module of our processing.

First, let's create an external processing in the configurator using the File/New menu. In the window that appears, select "External Processing".

The procedure itself should look like this:

Procedure Initialize(Object, TablePartName, TableField) Export;

For each RowTablePart from Object[TablePartName] Loop

TabularPartString.Result = Env(TablePartString.Result);

EndCycle;

EndProcedure

In this example, it was necessary to round the results of payroll in the document "Payroll" in ZUP 2.5. You prescribe the actions you need with the tabular part of the document. The procedure must be called "Initialize", contain three parameters and the keyword "Export".

After we have written what the processing should do, we save it and go to the 1C Enterprise mode, where we register the processing in the directory of external processing.

Be sure to select the attribute type - "Filling tabular parts". Add a row to the table and fill in all the required fields. The object representation is the document on which to call our processing. Tabular part - the name of the tabular part, because There may be more than one in a document. And the button view is how the button will look in the “Fill” menu above the tabular section.

After completing all the steps, we write the element and go to the desired document. We see that a new button has appeared above the tabular part. We use and rejoice.)

I hope this article helped you create a mechanism for filling or processing a tabular section. If not, you can always and I will write any processing for you.)

You can also download for example the processing that turned out during the writing of this article, for this, click on the link below.