In this article, we will consider step-by-step instructions for creating external processing in 1C 8.3 in the managed application mode, respectively, we will use managed forms. And most importantly, we will learn how to connect it to the mechanism of "external processing" of 1C configurations built on the library of standard subsystems version 2.0 and newer.
The task will be the following: to create the simplest external processing that will perform a group action on the "Nomenclature" reference book, namely, to set the selected percentage of the VAT rate for the specified group of items.
To do this, we will immediately make the necessary settings in the program (the configuration 1C 8.3 is considered: “Enterprise Accounting 3.0” on managed forms).
Checking this box gives us the ability to use external processing.
Creating a new external processing in 1C 8.3 by example
Now let's go to the configurator. Select "New..." from the "File" menu. A window for selecting the type of file to be created will open. Select "External Processing":
A new external processing window will open. Let's give her a name right now. It will be offered when saving the processing to disk:
Let's add a new managed processing form. We indicate that this is the processing form and it is the main one:
On the form we will have two props:
- Nomenclature group - link to the reference book "Nomenclature";
- SelectVAT Rate – a link to the listing of the VAT Rate.
We create details in the "Props" column in the upper right window. Drag them with the mouse to the upper left window. The new details should immediately appear on the form below.
The sequence of details can be changed with the arrows "Up" - "Down":
Get 267 1C video lessons for free:
It remains to add the "Install" button. In managed forms, you can't just add a button to a form. Even if you add it to the structure of the form elements, it will not be visible on the form itself. The button must be associated with the command that it will execute. Go to the "Commands" tab and add the "Set VAT Rate" command. Create an action in the command properties. Select the command handler "On the client". A command can also be added to the form by simply dragging and dropping it into the section with form elements.
A procedure of the same name will be created in the form module. In it, we call the procedure on the server:
&AtClient
Procedure Set VAT Rate (Command)
SetVATRateOnServer();
EndProcedure
In the procedure on the server, we will write a small query and actions related to setting the VAT rate:
&On server
Procedure SetVATRateOnServer()
Request = New Request;
Request.Text =
"CHOOSE
| Nomenclature.Link
| FROM
| Directory. Nomenclature AS Nomenclature
|WHERE
| Nomenclature.Reference IN HIERARCHY (&Nomenclature Group)
| AND NOT Nomenclature.Deletion Mark
| And NOT the Nomenclature. This is the Group ”;
Query.SetParameter("Nomenclature Group", Nomenclature Group);
RequestRes = Request.Execute();
SelectDetRecords = ResRequest.Select();
While SelectDetRecord.Next() Loop
Attempt
SprNo.Object.Write();
Exception
Report("Error writing object """ + SprNoobObject + """!
|» + DescriptionError());
End of Attempt;
EndCycle;
EndProcedure
We return to the "Form" tab, add a button to the form and associate it with the command:
As such, our processing is ready to use. To call it, in the "1C Enterprise" mode, you need to go to the menu "File" - "Open" and select the created file.
However, working in this mode is convenient for debugging processing, and it is not quite suitable for the user to work with. Users are used to having everything “at hand”, that is, in the database itself.
For this, the section "Additional reports and processing" is used.
But in order to add our processing there, we must first give it a description and tell the program its properties.
Description of External Processing Details
I will give an example of the contents of this function. It must be exportable and, accordingly, located in the processing module:
Function DetailOnExternalProcessing() Export
DataForReg = New Structure();
DataForReg.Insert("Name", "Setting the VAT rate");
DataForReg.Insert("SafeMode", True);
DataForReg.Insert("Version", "ver.: 1.001");
DataForReg.Insert("Information", "Processing for setting the VAT rate in the Nomenclature directory");
DataForReg.Insert("View", "AdditionalProcessing");
TabZnCommands = New TableValues;
TabZnCommands.Columns.Add("Identifier");
TabZnCommands.Columns.Add("Usage");
TabZnCommands.Columns.Add("View");
NewLine = TabZnCommands.Add();
NewString.Identifier = "OpenProcessing";
NewLine.Usage = "FormOpen";
NewLine.View = "Open Processing";
DataForReg.Insert("Commands", TabZnCommands);
Return DataForReg;
EndFunctions
To better understand which fields of the registration data structure you need to use, let's look at the details of the "Additional reports and processing" directory:
As you can see, everything is quite simple. Only one attribute does not match: “Launch Option” - “Use”. If we look at the code of one of the common modules, we will see how a bunch of these fields arise:
To determine which fields of the structure are required, you can first not describe it, just create an empty one, and then use the debugger. If you trace the modules when registering processing, it becomes immediately clear which fields are required and which are not.
Connecting external processing in 1C 8.3
To work with external processing (and the external printing form is also an external processing), there is an object External Processing.
Let's consider two possible cases:
External processing is stored on disk separately from the infobase
To programmatically open external processing in 1C, you need to know the address of its file. Knowing it, you can either open the processing form, or get the processing object for further actions with it (for example, to call export functions from the object module).
Opening an external processing form
To programmatically open an external processing form in 1C, use the function GetForm() object External Processing. The function has several parameters. Consider a simple opening of the main processing form:
Shape= ExternalProcesses. GetForm(FileAddress) ;
Form. Open() ;
To open a non-main external processing form, you must specify its name.
//The FileAddress variable contains the full path to the external processing file
Shape= ExternalProcesses. GetForm(FileAddress, "MinorForm") ;
Form. Open() ;
Opening external processing as an object
In order to get external processing as an object, the function is used Create() object External Processing.
//The FileAddress variable contains the full path to the external processing file
ProcessingObject= ExternalProcessings. Create(FileAddress) ;
By default, all processing opens in safe mode. To disable it, use the following options:
//The FileAddress variable contains the full path to the external processing file
External processing or printing form is saved in the infobase
In many configurations, it is possible to save external printing forms and processing directly in the infobase. For this, a guide is used. External Processing. The external processing itself is stored as binary data or in an attribute StorageExternalProcessing, or in the tabular section Affiliation in props StorageExternalProcessing.
To open external processing you need:
- Get it from storage.
- Save the processed file to disk.
- Open a form or get a processing object.
- If we are dealing with an external printing form, then you can fill in the standard requisite ReferenceToObject and call the export function Seal.
//ReferenceReference variable contains a reference to the ExternalProcessing directory element
dvData = RefReference. StorageExternalProcessing. Get() ;
FileAddress= GetTemporaryFileName() ;
DvData. Write(FileAddress) ;
ProcessingObject= ExternalProcessings. Create(FileAddress, False ) ;