1c external printing form processing parameters. Output of printed forms with a request for data in the "Print documents" form from the BSP "Print" subsystem

Let's consider writing the simplest printed form in 1s 8.1 - 8.2 using configuration example Enterprise accounting 2.0. Let's say you need to write an external printed form for a document: display the basic data of the document, as well as from the tabular part Goods: nomenclature, price, quantity and amount.

You can download the resulting example from .

In the configurator 1C Enterprises 8 create external processing ( File->New->External Processing), set the name, create the required details for the external printed form Object Reference with type DocumentLink. Sales of Goods and Services.

Creating a printed form layout

Add a new one layout, leave the layout type spreadsheet document. We create three areas on the layout: Header, Data And Basement. This can be done by selecting the required number of lines and clicking menu Table->Names->Assign name (Ctrl+Shift+N).

After this, we begin to place text and parameters in the areas. We'll put it in the header name of the printed form, document number And organization, and also draw the borders of the table header and write the names of the columns. When creating a parameter in the cell properties, on the Layout tab you should set the property Filling in meaning Parameter.

In area Data let's create parameters for displaying rows in the tabular section( Nomenclature, price etc.), and in the area Basement for totals by quantity and amount.

Programming

Let's go to the printing form object module Actions->Open object module.

Let's create an export function there that is mandatory for printed forms. Seal().

Function Print () Export EndFunction

In the function we will create a variable for spreadsheet document, into which the printed form will be output, we get layout And layout areas.

TabDoc = new TabularDocument; Layout = GetLayout("Layout" ); HeaderArea = Layout.GetArea("Header" ); AreaData = Layout.GetArea("Data" ); AreaFooter = Layout.GetArea("Footer" );

Let's fill in the parameters hats and bring it to spreadsheet document .

HeaderArea.Parameters.HeaderText = +LinkToObject.Number; HeaderArea.Parameters.Organization = LinkToObject.Organization; TabDoc.Output(HeaderArea);

To get table rows Goods we use the request.

Request = new Request; Request.SetParameter("Link", ObjectLink); Query.Text = "SELECT | Sales of Goods and Services Goods. Nomenclature, | Sales of Goods and Services Goods. Amount, | Sales of Goods and Services Goods. Price, | Sales of Goods and Services Goods. Quantity|FROM | Document. Sales of Goods and Services. Goods HOW to Sale of Goods and Services Goods|WHERE | Sales of Goods and Services Goods. Link = &Link";

We pass the details to the request parameter Object Reference, to indicate in the condition WHERE, that we need data only from the document from which we derive the printed form. To get a sample query, we first execute it and then select the rows.

Select = Query.Run().Select();

Next in the loop we fill in the area parameters Data for each line of the document sample and display them in spreadsheet document. We also calculate the total values ​​in the loop quantities And amounts. We will not fill in each parameter separately, but use the procedure Fill inPropertyValues((<Приемник>, <Источник>) from global context, it copies property values <Источника> to properties <Приемника> . Matching is done by property names. You can read more about this in syntax assistant 1C Enterprise 8.

TotalSum = 0 ; TotalQuantity = 0 ; While Selection.Next() Loop FillPropertyValues(AreaData.Parameters,Selection); TotalSum = TotalSum + Sample.Sum; TotalQuantity = TotalQuantity + Sample.Quantity; TabDoc.Output(AreaData); EndCycle ;

Fill and display the area Basement.

AreaFooter.Parameters.TotalQuantity = TotalQuantity; AreaFooter.Parameters.TotalSum = TotalSum; TabDoc.Output(AreaFooter);

Returning the completed spreadsheet document from the function Seal().

return TabDoc;

If you are using one of the standard configurations, then after returning the spreadsheet document 1C will display the printed form on the screen. You can also use the spreadsheet document method for output. Show().

5. Connecting a printed form to a document

IN standard configurations 1C 8 There is a directory for registering external printed forms ExternalProcessing. To connect, go to the menu in enterprise mode Service->Additional reports and processing->Additional external printed forms.

Add new element directory, load the printed form from the disk and select the document type.

Now in the document Sales of goods and services A new printable will appear.

Auto-registration of printed form

To ensure that when connecting a printing form you do not need to select the document type manually, you can configure auto-registration. To do this, add a new layout and call it Settings_Auto-registration(this is the only way) and in its first cell we write Documentation.<Наименование документа> (or Directories.<Наименование справочника> ).

Now, when connecting a printing form, we will be asked to use auto-registration parameters.

Everyone has seen more than once how, in typical configurations built on the basis of the BSP (Library of Standard Subsystems), printed forms built on the basis of a Spreadsheet document are output to a special form “Print Documents”. This form is part of the “Print” subsystem from the BSP. When developing your own printed forms, sometimes it is necessary to request from the user additional data necessary for printing. Here the question arises, how in this case to display the printed form in the “Print Document” form. In this article, I will look at how to implement the output of a printed form to the mentioned form from the “Print” subsystem, if we want to request additional data from the user before outputting the printed form. Two cases will be considered here: when a printed form is implemented using the “Additional reports and processing” subsystem and when a printed form is added to the configuration in configurator mode, i.e. changes are made to the standard configuration.

The "PrintDocuments" form provides some additional functions when working with printed forms, such as:

  • button to print to a printer, directly in the form;
  • indication of the number of copies, printed form;
  • editing the generated printed form;
  • the ability to save a printed form in various data formats (Excel, Word, PDF, etc.);
  • sending a printed form by email;
  • Convenient work with a set of documents.

This form is now used by 1C in all standard configurations to display printed forms of documents and directory elements. And of course, when developing our own printed forms, in order not to go beyond accepted practice, we should also display our printed forms using the tools provided.

When using standard methods for adding printed forms, the “Print” subsystem will do everything for us and display the printed form as needed. For example:

  1. When adding a print command to a document using the "Print" subsystem, we need to describe the print command in the Add Print Commands procedure, indicating the print manager in which the Print procedure is implemented;
  2. When creating Additional Processing, we need, in the processing object module in the InformationOnExternalProcessing function, to describe a command with the use type Call of a server method and immediately implement the Print procedure, which in a certain way implements the call to generate a printed form.

In such cases, as I already said, the printing subsystem will output the printed form we generated itself, as needed. Such methods involve the direct formation of a printing form, i.e. passed the objects to be printed to the print procedure, generated a spreadsheet document and displayed it on the screen.

What if, before starting to generate a spreadsheet document, you need to request some data from the user? Those. we need to show the form. In this case, the standard order of forming a printed form is violated and we need to think about how to transfer our printed form to the “Print Documents” form.

In this case, two situations are possible:

  1. When a printing plate is created with a configuration change;
  2. When a printed form is created without changing the configuration, i.e. The subsystem "Additional reports and processing" is used.

We create a printed form by adding it through the configurator.

First variation. Through the creation of processing with the team.

This option involves adding processing directly to the Metadata Objects:

Let's consider the option when we need to implement a printed form of a certain object, for example, a directory element. To do this, we need to work in four processing areas:

  1. Create a command that will call our printable form;
  2. Create the form itself;
  3. Create a layout of a printed form;
  4. Make changes to the processing manager module.

Creating a team

Specify in the command properties:

  • The group where we want the command to be displayed in the form;
  • The parameter type is exactly the reference book or document whose printed form we are making;
  • The mode of using the parameter is Multiple. So that you can display printed forms for several elements selected in the list at once.

In the command module, we open the processing form, passing its selected directory elements for which it is necessary to generate printed forms. Let’s not split hairs here and slightly correct the standard code that the platform inserts into the command processing procedure:

&On the ClientCommand Processing Procedure(Command Parameter, Command Execution Parameters) //Insert the contents of the handler. FormParameters = New Structure("DataForPrinting", CommandParameters); OpenForm("Processing.PrintForm.Form",FormParameters,CommandExecutionParameters.Source,CommandExecutionParameters.Uniqueness,CommandExecutionParameters.Window,CommandExecutionParameters.NavigationLink); End of Procedure

The procedure parameter Command Parameter precisely contains the elements we have selected for printing.

Creating a form

Let's add a form to processing, create a form attribute of the List of Values ​​type and the necessary input details for us additional parameters for printing form:

DataForPrint - type ListValues;

Number of Rows - type Number.

My example will be purely demonstrative, so let’s conditionally determine that my goal is to print out the representation of the selected element and the number of lines that we select as an additional parameter on the form.

Go to the form module and write the following code:

&OnServerProcedureWhenCreatingOnServer(Failure, StandardProcessing)PrintData.LoadValues(Parameters.PrintData); End of Procedure &On the Client Procedure Print (Command) Print ManagementClient. Execute Print Command("Processing.PrintForm", //Print Manager "PrintForm", //Identifier GetObjectsForPrint(), //PrintObjectsThisObject, //Owner of the form - the form from which print is called GetPrintParameters( )); //Print options - arbitrary parameters for transfer to the print manager End of Procedure &On the Server Function GetObjectsForPrint() Array = DataForPrint.UploadValues(); Return Array; EndFunction &OnServer Function GetPrintParameters()PrintParameters = New Structure; Print Options.Insert("Form Title", "Print Form"); //One of the parameters for the "Print document" form. //Specifies the title of the printable output form. //Here we add our parameters, which we want to additionally transfer to the print manager. PrintOptions.Insert("Number of Rows", Number of Rows); ReturnPrintOptions; EndFunction

We define the WhenCreatingOnServer procedure and in it we read from the parameter that we passed from the command when opening the form, the list of objects for which we need to generate a printed form.

We create a Print command in the form and write its handler, in which we call the function of the general module ManagePrintClient.ExecutePrintCommand, we set required parameters this function, namely:

  • Print Manager - the name of the object in the manager module, which is defined by the Print function, which forms our printed form;
  • Identifier - identifier of the printing form that needs to be printed. Using this identifier, we will select in the Print function of the manager module which printing form needs to be printed;
  • Printing objects are directly those objects for which printing forms are generated;
  • Owner of the form;
  • Printing parameters - here we create and pass a structure with printing parameters, here we pass our additional parameters that we requested from the user in the processing form.

Actually, by calling the function ExecutePrintCommand from the processing form, we solve our problem of outputting the printed form to the “PrintDocuments” form. Then the “Print” subsystem will perform standard actions and bring the execution to the Print procedure, which we must define in the manager module of our processing.

Creating a printed form layout

Making changes to the processing manager module

From this moment on, we carry out standard actions for developing printed forms using the “Print” subsystem from the BSP.

Add the following code to the manager module:

Procedure Print (Array of Objects, Print Parameters, Collection of Print Forms, Print Objects, Output Parameters) Export If Print Control. Need to Print Layout (Collection of Print Forms, "Print Form") Then Control Print. Output Tabular Document to Collection (Collection of Print Forms, "Print Form") Form", NStr("ru = "Print form""), PrintLayout( Array of Objects, Print Parameters), "Processing.PrintForm.PF_MXL_PrintForm",); endIf; End of Procedure &On Server Function PrintLayout(Object Array, Print Options) TabularDocument = New TabularDocument; //Create a spreadsheet document //////////////////////////////////////////// //////////////////////////////////////////////// ///////////////// //OVERRIGGED PART OF THE MODULE // //Here we create our printed form Layout = GetLayout("PF_MXL_PrintForm"); For each Object From Array of Objects Loop AreaHeader = Layout.GetArea("Header"); RegionObject = Layout.GetArea("Object"); TabularDocument.Output(HeaderArea); AreaObject.Parameters["Object"] = Object; TabularDocument.Output(AreaObject); For Account = 1 ByPrint Options["Number of Rows"] Cycle AreaLine = Layout.GetArea("Line"); AreaString.Parameters["String"] = Count; TabularDocument.Output(AreaString); EndCycle; TabularDocument.OutputHorizontalPageSeparator(); EndCycle; //OVERDEFINED PART OF THE MODULE ///////////////////////////////////////////// //////////////////////////////////////////////// ///////////////// Return TabularDocument; //Return the table document End of Function

Second option. Through the implementation of the print command.

This option is very similar to the first one in terms of printing implementation. Its difference is in the way of creating a command that will be displayed in the interface and start our printing.

In this case, when defining a print command, we also use the “Print” subsystem from the BSP. Instead of defining a command for opening processing in the processing itself, we need to go to the manager module of the object to which we want to add a printing form, and specify a description of the printing command in the procedure AddPrintCommands(PrintCommands):

Procedure AddPrintCommands(PrintCommands) ExportPrintCommand = PrintCommands.Add(); PrintCommand.Identifier = "PrintForm"; PrintCommand.View = NStr("ru = "Print a printed form""); PrintCommand.Handler = "GeneralModulePrintForm.ProcessingPrintFormCommand"; PrintCommand.Order = 100; End of Procedure

Here we add a print command called “Print printed form” to all directory forms (I remind you that we are working with the counterparties directory). And here is the main point that must be taken into account. You can add two types of commands to the form:

1. Calling the Print procedure from the manager module;

2. Calling a client method.

This is exactly what we need to call the client method. The client method will allow us to call a processing form in which we will request the data we need from the user before printing.

To implement such a call, it is necessary to specify a Handler for it when defining a command (see the code above). A string containing the path to the client function is passed to the Command Handler, i.e. path to the Export function of the common module on the client. It is this function that will be called when you click on the print command that we add to the forms.

As you understand, for this to work, you need to create this very General Module and define the Export function. Therefore, we write the following code in our general module:

Function ProcessingPrintCommandPrintForm(PrintParameters) Export //Insert the contents of the handler. FormParameters = New Structure("DataForPrint", PrintParameters.PrintObjects); OpenForm("Processing.PrintForm.Form", FormParameters); EndFunction

Here we do the same thing as during the first implementation, open the print form, only now our Print Data will be contained in the parameter passed to the Print Parameters function, or rather in its Print Objects field.

After we open the processing form, all actions are similar to the first option.

The implementation of this option can be found in standard configurations, in mechanisms associated with printing consent to the processing of personal data.

We create additional processing.

What if this is not our configuration and it is being supported? And in general, we don’t want to go into the configuration and edit it?

In this case, we need to use the “Additional reports and processing” subsystem from the BSP.

With this solution, we need to write code in only two places and all of them are in our future additional processing:

1. Processing object module;

2. Processing form module.

In the object module we write the following code:

//////////////////////////////////////////////// //////////////////////////// // PROGRAM INTERFACE #ProgramInterface area // Returns information about external processing. Function InformationOnExternalProcessing() ExportRegistrationParameters = AdditionalReportsAndProcessing.InformationOnExternalProcessing("2.2.2.1"); Registration Parameters.View = AdditionalReportsAndProcessingClientServer.ProcessingViewPrintedForm(); Registration Parameters.Version = "1.0"; NewCommand = Registration Parameters.Commands.Add(); NewCommand.Presentation = NStr("ru = "External printed form with preliminary data request""); NewCommand.Identifier = "ExternalPrintForm"; NewCommand.Use = AdditionalReportsAndProcessingClientServer.CommandTypeOpenForm(); NewCommand.ShowAlert = True; NewCommand.Modifier = "PrintMXL"; ReturnRegistrationParameters; EndFunctions Procedure Print(Print Data, PrintForms Collection, Print Objects, Output Parameters) Export If PrintManagement.NeedPrintLayout(PrintFormsCollection, "ExternalPrintForm") Then PrintManagement.OutputTabularDocumentIntoCollection(PrintFormsCollection, "ExternalPrintForm" PrintForm", NStr("ru = "Exam sheet""), PrintLayout(PrintData ),); endIf; End of Procedure &On Server Function PrintLayout(PrintData)PrintParameters = PrintData.Value; //Receives print parameters from the first element of the Value List Object Array = PrintData.Copy(); //Copy the list of values ​​ArrayObjects.Delete(0); //Delete the lines of the copied element containing Printing Options TabularDocument = New TabularDocument; //Create a spreadsheet document //////////////////////////////////////////// //////////////////////////////////////////////// ///////////////// //OVERRIGGED PART OF THE MODULE // //Here we create our printed form Layout = GetLayout("Layout"); For each Object From Array of Objects Loop AreaHeader = Layout.GetArea("Header"); RegionObject = Layout.GetArea("Object"); TabularDocument.Output(HeaderArea); AreaObject.Parameters["Object"] = Object; TabularDocument.Output(AreaObject); For Account = 1 ByPrint Options["Number of Rows"] Cycle AreaLine = Layout.GetArea("Line"); AreaString.Parameters["String"] = Count; TabularDocument.Output(AreaString); EndCycle; TabularDocument.OutputHorizontalPageSeparator(); EndCycle; //OVERDEFINED PART OF THE MODULE ///////////////////////////////////////////// //////////////////////////////////////////////// ///////////////// Return TabularDocument; //Return the spreadsheet document EndFunction #EndArea

There are two functions and one procedure.

The standard function for Additional processing is InformationOnExternalProcessing(); without it, the system will not understand that this is additional processing. Here important point is, an indication that the command implemented in this processing is of type Opening a form. Those. we will open the form as we need. Next comes the definition of the Print procedure and the function that directly generates our spreadsheet document.

Here you need to pay attention to the fact that the print command in this case should contain only 4 parameters, and not 5 as is the case with the usual definition of the print command in the manager module. IN in this case There is no parameter for passing Print Settings. Therefore, we will have to be creative in order to convey not only the objects themselves for which the printed form is generated, but also the parameters that we request from the user in the form.

And so we have defined additional processing, the command from which will open the processing form. Therefore, the next step is to create a processing form.

In this form, we need to create three details to store the values ​​that we will need later. Let's call these details as follows:

Command ID - type String

ObjectsAssignments - type List of Values

In the module of this form we write the following code:

&On the Server Procedure When Created on the Server (Failure, StandardProcessing) //When creating on the server, remember the standard parameters passed by the AdditionalReportsAndProcessing subsystem AdditionalProcessingLink = Parameters.AdditionalProcessingLink; CommandIdentifier = Parameters.CommandIdentifier; Destination Objects.LoadValues(Parameters.Destination Objects); EndProcedure &OnClient Procedure Print(Command) // Get the uniqueness key of the form being opened. UniqueKey = String(New UniqueIdentifier); //Defining and filling out standard parameters for the general form Print DocumentsOpening Parameters = New Structure("DataSource, SourceParameters"); OpeningParameters.DataSource = AdditionalProcessingLink; OpeningParameters.SourceParameters = New Structure("CommandIdentifier, DestinationObjects"); OpeningParameters.SourceParameters.CommandIdentifier = CommandIdentifier; //Objects to be printed and parameters entered in the form will be processed //we will pass through the parameter Source Parameters.Destination ObjectsOpening Parameters.Source Parameters.Destination Objects = GetDestination ObjectsAndPrint Parameters(); OpenForm("GeneralForm.PrintDocuments", OpeningParameters,FormOwner,UniqueKey); End of Procedure &On the Server Function GetDestinationObjectsAndPrintParameters()PrintData = DestinationObjects.Copy(); //////////////////////////////////////////////// //////////////////////////////////////////////// //////////// //OVERRIGGED PART OF THE MODULE // //Here we create the Print Parameters structure and fill it with the parameters //that need to be passed to the print function Print Parameters = New Structure; PrintOptions.Insert("Number of Rows", Number of Rows); PrintData.Insert(0, PrintOptions); //OVERDEFINED PART OF THE MODULE ///////////////////////////////////////////// //////////////////////////////////////////////// ///////////////// ReturnPrintData; EndFunction

In the When CreateOnServer procedure, we fill in our three details that we created to store the parameters passed to the processing form.

Next, we define a handler for the print button on the form. In this handler, we need to open the “Print Documents” form ourselves; for this we need to prepare the Opening Parameters of a certain structure. In this structure, at a minimum, two fields must be defined:

Source Parameters, which include Command Identifier and Destination Objects:

Command ID - also saved when created on the server, this is the identifier of the command that called our processing form. Therefore, using the identifier, we will determine what we need to print in the Print procedure in the object module.

Assignment Objects - it is in this field that we need to pass an array of objects for which the printed form is generated, as well as the parameters requested from the user in the form.

How I define destination objects can be seen in the function GetObjectsDestinationsAndPrintOptions. Here I copy our destination objects from the form props, in place of the array element with index 0, I paste our print parameters.

In the future, the array defined in this way will be transferred from the “Print Documents” form as the first parameter of the Print object module procedure, which we defined earlier.

If we return to the definition of the processing object module and look at the PrintLayout function, in the first three lines of the function you can see how I extract our parameters and objects from the data transferred to the Print procedure and then work with them.

Such manipulations with the Assignment Objects parameter are determined by the specifics of calling the Print object module procedure. You can track for yourself how parameters are passed and function calls are made by opening the Document Printing form module.

Result.

As a result of such manipulations, we will receive three commands on the form from which we want to display the printed form:

The numbering of commands corresponds to the order of implementation options.

All of these commands will do the same thing:

Show additional parameters request form

Output generated printed forms to the "Print documents" form. Exactly what we wanted:

P.S. As templates, to implement my own printed forms with a request for additional parameters, I upload both processes that are involved in all three methods of generating a printed form.

This article will tell you in detail how a beginner with little knowledge of 1C 8 can create a printed form. For example, let's take one of the most common 1C 8 configurations - Accounting 2.0. Creating a printed form 1C stages of writing:

  • Creating an external printing form file;
  • Creation of a printed form layout;
  • Writing program code to display printed form data on the screen;
  • Creating parameters for auto-registration of a printed form;
  • Connecting an external printing form to the base 1C Enterprises.

Creation of a printed form 1C. Formulation of the problem

We are required in the configuration Accounting 2.0 create a printed form for a document Receipt of goods and services. In the header of the printed form, display the following data:

  • Organization;
  • Counterparty;
  • Counterparty agreement;
  • Date of receipt.

Display the data in the tabular section as a table Goods document. The table should include the following columns:

  • Nomenclature;
  • Quantity;
  • Price;
  • Sum;
  • And also the price of the item for the current date (by type of price from the document).

External processing file

Let's move on to solving the problem. First, let's open 1C 8 in mode Configurator. It is in this mode that all developments are carried out on the 1C 8 platform. Now we need to create an external processing file. To do this, click on the menu File -> New… or by the icon of a new file.

In the window that opens, select the item External processing.

Next in the field Name You must enter the name of the external processing. In our case, we’ll simply call it “PrintForm”; the synonym field will be filled in automatically. Please note that in the field Name, external processing, the name should be written without spaces or punctuation marks.

Let's add external processing attributes LinkToObject and select type for him DocumentLink. Receipt of Goods and Services. To do this, in the 1C external processing metadata tree, select the item Requisites and press the button Add(button with green plus). The attribute properties window will open on the right side of the screen, in the field Name let's write - ReferenceToObject. IN field Type press the button with three dots.

Let's expand the branch in the type tree DocumentLink, and find the element Receipt of Goods and Services there, check the box next to it and click OK.

Let's save the external processing file to HDD, for this we will use the menu File -> Save, pictogram Save(blue floppy disk), or a keyboard shortcut Ctrl+S. Let's name the saved file “PrintForm”.

Creating a printed form layout

Let's start creating a layout of the 1C printing form. The layout serves as a template for the output of the printing form, so if you want your printing form to look good, you should pay attention to it.

Let’s add a new layout in the external processing metadata tree; we won’t change anything in the layout designer window and click the button Ready.

In the new layout that opens, we will create several areas necessary for displaying the printed form. All the layout areas we need will be horizontal, so to create a new area, select the required number of layout lines and go to the menu Table -> Names -> Assign name or use keyboard shortcut Ctrl + Shift + N, then enter the name of the region in the box. When creating a layout area, don’t be afraid to make a mistake with the number of lines; you can always add or remove them. To delete a 1C layout line, select the desired line and select context menu paragraph Delete. To add a new line to the layout, select any line of the layout and select the item in the context menu Expand.

Adding a Layout Header

First of all, let's create an area A cap, it will display the data for the header of the printed form. For this area we will need seven layout lines. Let's select them and, as I wrote above, press the key combination Ctrl + Shift + N, in field Name write “Hat” and press the button OK.

Let's fill the layout area with the data we need. Usually, no printed form is complete without a title, so let’s create one in our layout header as well. Since in the title, in addition to the name of the printed form, we will also display the number of the document from which it was printed, we will set the text of the title in the layout as a parameter. A layout parameter is a specially designated layout cell into which various data can be output using the built-in 1C 8 language. The title should be displayed across the entire width of the printed form, so let’s decide how many layout cells will be enough for us to print on a standard landscape orientation leaf.

Usually thirteen or fourteen layout cells are enough, select them in the first row of the area A cap and combine into one cell ( Context menu -> Merge). After this, double-click on the resulting large cell and write the name of the parameter, in our case “TitleText”. In order for the entered text to become a full-fledged parameter, right-click on the cell and select the item in the context menu Properties. On the bookmark Layout let's find the field Filling and select the value Parameter. Parameters in the 1C layout are indicated by brackets “<>».

The heading of the printed form should stand out among other text, so select the cell again and use the icons on the layout formatting panel to set the text alignment Centered and font size 14.

After the title text we will display it in the area A cap information about the organization, counterparty, counterparty agreement and date of receipt of goods. Since all this data is also taken from the document, we will also formalize it with parameters. In addition, before each parameter you should write explanatory text so that the user can easily understand where the organization is, where the counterparty is, etc. All these actions are similar to creating a title, so I won’t dwell on them in detail, I’ll just give a picture of what should happen in the end.

The figure shows how the layout parameters differ from regular text.

Adding a Layout Table Header

The last thing we need to create in this layout area is the table header, into which the data of the tabular part will be displayed Goods. The columns required for the table were described in the “Problem Statement” section. We will also create a table header using a combination of cells and writing text (column names). Select the borders of the table header using the tool Frame, which is located in the layout formatting panel.

Adding a table to a layout

Let's create another area in the layout - Data. The data table of the tabular part will be displayed in it Goods. For this area, we only need one line of layout. To display all the rows of the tabular part in a printed form, we will fill and display this area the required number of times. Columns in the area Data should coincide with the columns of the table header, so filling it out will not be difficult. The only difference is in the area Data we need parameters, not just text. Also note that by default, numeric parameters are formatted to the right and text parameters are formatted to the left. To select columns, you also need to use the tool Frame.

Adding a Footer to a Layout

The last layout area we need is Basement. It will display totals by quantity and amount. Creation is similar to creating an area Data, but additionally the results should be highlighted in bold.

The end result should be a layout that looks like this:

Creation of a printed form 1C. Programming

Let's start programming - this is the most important stage in creating a printed form. First of all, let's go to the external printing form object module, this is where we will program. To do this, in the main external processing window, click Actions -> Open object module.

You need to create an export function in the external printing form object module Seal().

Function Print() Export EndFunction

note that this function is mandatory for external printing forms in configurations using normal application. All subsequent program code necessary to display the printed form will be written inside this function.

Initializing Basic Variables

Let's create a variable TabDoc, which will contain a spreadsheet document - this is exactly the printed form into which we will display the filled areas of the layout.

TabDoc = new TabularDocument;

To a variable Layout We will get the printed form layout we created. To do this we use the built-in function GetLayout(<ИмяМакета>).

Layout = GetLayout("Layout");

We will convert all areas of the layout into variables. To do this we use the layout method GetArea(<ИмяОбласти>) .

HeaderArea = Layout.GetArea("Header"); AreaData = Layout.GetArea("Data"); AreaFooter = Layout.GetArea("Footer");

Outputting the header of a printed form into a spreadsheet document

All necessary variables are initialized. Let's start filling and displaying the layout areas in a spreadsheet document. First of all, let's fill in the title of the printable form; for this we need to pass in the parameter Title Text, which we created in the layout, the text we need. To fill in the parameter values ​​for the layout area, there is a special collection called - Options. From which through “.” you can get any parameter. In the header text we will transfer the text: “Printed form”, as well as the document number.

Header Area.Parameters.TitleText = "Print form"+LinkToObject.Number;

We will fill in the remaining parameters of the header in a similar way; we will obtain all the necessary values ​​for them from the details Object Reference, which contains a link to the document to be printed.

HeaderArea.Parameters.Organization = LinkToObject.Organization; HeaderArea.Parameters.Account = LinkToObject.Account; HeaderArea.Parameters.ReceiptDate = ObjectLink.Date; Header Area.Parameters.Counterparty Agreement = LinkToObject.Counterparty Agreement;

All parameters of the header are filled in, we will display it in the spreadsheet document we created, for this we use the method Output(<Область>) .

TabDoc.Output(HeaderArea);

Writing a request for a printed handicap

Let's start filling and drawing out the area Data. Creating a 1C printed form also involves writing a query; we need it to obtain tabular data Goods and prices Nomenclatures for the current date we will use Request. The 1C 8 query language is similar to SQL, or rather practically copies its capabilities SELECT statement, but the entire request is written in Russian. Therefore, if you are at least vaguely familiar with SQL, then you will easily understand the 1C 8 query language.

In this printed form, the request will be quite simple and many will say that it would be possible to do without it, but knowledge of the query language and the ability to use it competently is one of the main skills of a 1C programmer. Queries allow you to obtain complex data samples using fewer resources, and the query text is much easier to understand than program code written without using a query (or with minimal use of it). In addition, 1C 8 has very good designer queries, which allows you to interactively assemble a query from the necessary tables.

Let's create a variable that will contain the request.

Request = New Request;

We will compose the request text using the request constructor. To begin with, let's write:

Request.Text = "";

Place the mouse cursor between the quotes and click right button mice. In the context menu that opens, select the item Request constructor, it will help us a lot in creating a 1C printing form. After this, the query designer window will open; it contains many tabs, but for our query we will only need four: “Tables and Fields”, “Relations”, “Conditions”, “Joins / Aliases”.

For our query we will need two tables: table part Goods document Receipt of goods and services and a snapshot of the latest information on the current date of the register Item prices.

On the left side of the designer window we find the column Database. It contains a tree of all metadata objects, let's find the ones we need. To do this, let's open the thread Documentation and find the document Receipt of Goods and Services, let's open it and find the tabular part Goods, drag it into the column of the query designer Tables. You can drag in three ways: by actually dragging, double click according to the table or by selecting it and pressing the “>” button. Let's open the thread Information Registers and find a table there PricesNomenclature.ShortcutLatest, also drag it into the column Tables. These two tables are enough for our query.

Let's select the fields we need from the resulting tables. To do this, in the column Tables let's open the table and find the fields: Nomenclature, Amount, Price, Quantity and drag them to the third column of the constructor - Fields. Let's expand the table , let's find the field Price and also drag it to Fields.

The structure of the tables and fields of our request is ready, now let’s move on to the conditions. We need the tabular data Goods were not taken from all receipts, but only from the one that we print. To do this, we will impose a condition on the table Receipt of GoodsServicesGoods. Let's go to the “Conditions” tab of the query designer. In a collumn Fields the tables we selected earlier are located, for the condition we will need a field Link from the table Receipt of Goods and Services Goods, Let's drag it into the Conditions window.

In 1C queries you can use parameters; they are needed to transfer data to the request. For example, if we want to limit the selection of documents to a specific document, then we can use a parameter to pass a link to this document to the request and use this parameter in the condition. This is exactly what we will do in our request.

After the window Conditions we added a field Link, the query designer itself will create a parameter with the same name and place it after the “=” sign. This parameter You can rename it if you wish. In the request text, the parameters are marked with the “&” sign, but in this case this is not necessary, since it is assumed that the second part of the condition contains a parameter, you just need to remember this. How to pass a value to a 1C request parameter will be discussed below.

Since in the request we are using not a full table of product prices, but a virtual one (a slice of the latter in this case), we need to set the conditions for the formation of this virtual table, in our case this is the cut-off date and the condition for the type of prices (prices that have a strictly defined price type is the one specified in the receipt document that we print).

To fill in the parameters of the virtual table, go to the tab Tables and fields query constructor, in the column Tables select the table PricesNomenclatureCuttingLatest and press the button Virtual Table Options, located at the top. In the window that opens, in the field Period you should set a parameter to which the date on which the price cut will be made will be passed. In our case, this will be the current date (that is, today), so we will call the parameter “&CurrentDate”. In the conditions field we will write the conditions for the price type, we will also pass it in the parameter, which we will call “&TypePrice”. The resulting condition will look like this (where TypePrice- register measurement Item prices):

PriceType = &PriceType

The virtual table parameters are filled in, click the button OK.

Now that we have limited the selection to only the document we need, let's create connections between the query tables. If this is not done, then the prices from the PricesNomenclatureSliceLast table will not be associated with the item from the receipt. Let's go to the tab Connections query designer. Let's create a connection across the field Nomenclature between our two tables. To do this, press the button Add, in field Table 1 select a table Receipt of GoodsServicesGoods, and in the field Table 2 - PricesNomenclatureSliceLast. In the communication conditions, select the fields Nomenclature from both tables.

It should also be noted that in the query selection we need to get all the rows from the tab part Goods and prices only if they are available on the current date for the document price type. Thus, the tabular data Goods are mandatory, but price breakdown data is not available. Therefore, in the relationships between these tables, it is necessary to use the so-called LEFT JOIN, and the left (or required) table will be Receipt of GoodsServicesGoods, and the right (or optional) PriceNomenclatureSliceLast. In order for the left join of query tables to work as I described above, you need to check the box All after the field Table 1.


The request is almost ready, all that remains is to work a little on the field aliases. Let's go to the bookmark Unions/Aliases and set an alias for the field PricesNomenclature Slice Latest.Price. The nickname name will be - PriceAsToday, it is needed so that the names of the query selection fields and the names of the parameters in the printed form layout match.

The work in the query designer is now complete, click OK. After the designer window closes, you will see that the line with the request text is filled in and looks like this:

Request.Text = "SELECT | Receipt of Goods and Services Goods. Nomenclature, | Receipt of Goods and Services Goods. Amount, | Receipt of Goods and Services Goods. Price, | Receipt of Goods and Services Goods. Quantity, | Prices Nomenclature Slice of Latest. Price AS PriceToday | FROM | Document. Receipt of Goods and Services. Goods AS By stepProductsServicesProducts |LEFT CONNECTIONRegisterInformation.PricesNomenclature.SliceLast (| &CurrentDate, PriceType = &PriceType) HOW Nomenclature PricesSliceLast | ON Receipt of GoodsServicesProducts.Nomenclature | = PricesNomenclatureSliceLast.Nomenclature |WHERE | Receipt of GoodsServicesProducts.Link = &Link";

Executing the request

Let's pass the necessary parameters to the request; for this we will use the request method SetParameter(<ИмяПараметра>,<Значение>). To get the current date, use the built-in function The current date(), it returns the computer's date and time.

Let's run a query to get a sample with the data we need. To do this, first use the request method Run(), and then the method Choose().

Select = Query.Run().Select();

Filling out the printed form table

As a result, in the variable Sample will contain a selection of query results, you can navigate through it using the method Next(), and to go through the whole thing you need a loop Bye. The design will be as follows:

While Select.Next() Loop EndLoop;

It is in this loop that we will fill and display the layout area Data. But first, let's initialize two variables of numeric type. In them we will collect the totals by quantity and amount that we need to display in the area Basement.

TotalSum = 0; TotalQuantity = 0;

Inside the loop we will fill the area Data data from the current selection element into variables TotalAmount And TotalQuantity add sum and quantity values, and finally, display the area in a spreadsheet document using the method already familiar to us Output(). Since the names of the fields of our request completely coincide with the names of the area parameters Data, then to fill we will use the built-in procedure FillPropertyValues(<Приемник>, <Источник>), which copies property values<Источника>to properties<Приемника>.

While Selection.Next() Loop FillPropertyValues(AreaData.Parameters,Selection); TotalSum = TotalSum + Sample.Sum; TotalQuantity = TotalQuantity + Sample.Quantity; TabDoc.Output(AreaData); EndCycle;

Outputting the footer of a printed form into a spreadsheet document

It remains to fill and display the last area of ​​the layout - Basement. We have already prepared the data for filling, filling and withdrawal are carried out according to the same scheme.

AreaFooter.Parameters.TotalQuantity = TotalQuantity; AreaFooter.Parameters.TotalSum = TotalSum; TabDoc.Output(AreaFooter);

The spreadsheet document is completely filled out; all that remains is to display it on the screen so that the user can view the printed form and print it if necessary. But in typical 1C 8 configurations, the procedures of special modules are responsible for the output of external printed forms. Therefore, it is enough to return from the function Seal() completed spreadsheet document.

Return TabDoc;

At this point, the programming stage is completed and the creation of the 1c printing form is almost complete. Full text of the function Seal() I won’t give it here, you can look at it in the printable form file, which you can download at the bottom of the article.

Creation of a printed form 1C. Auto-registration options

When connecting an external printing form to the database, the system does not automatically determine which document or reference book the printing form is intended for; you have to select it manually. And if another person wrote the printed form, and you are only tasked with connecting it, then the choice may become ambiguous. In order to avoid such problems, in all external printed forms it is necessary to create a layout with auto-registration parameters. If it is created and correctly formatted, the system automatically determines which document or reference book the printed form is intended for.

It is done as follows:

  • In external processing we create a new layout. We call it “Settings_Auto-Registration” (it’s important not to make a mistake!).
  • In the first cell of the layout we write Documentation.(or Directories.) and the name of the document to which you need to connect the printed form.

Connecting an external printing form to the base

  • Start 1C 8 in mode Company;
  • Go to menu Service -> Additional reports and processing -> Additional external printed forms;
  • Click the button Add;
  • In the window that opens, click the icon Replace external processing file;
  • If you have created auto-registration parameters, then we agree to use them;
  • If you have not created auto-registration parameters, then in the tabular part Printing plate accessory add the required document or reference book;
  • Press the button OK.

After this, the external printing form will be available in the menu Seal document Receipt of goods and services. The creation of the 1C printed form can now be considered complete.