How to programmatically fill out and open a new document form? How to open a form of an existing object? Programmatically open the form of a new document 1s 8.3

Programmatically opening forms in a managed 1C application is significantly different from opening them in a regular application. Let's look at the old method first. It consists of receiving a form and then opening it in normal or modal mode (when opened in modal mode, the form blocks the program).

GetForm() . Open()

This is the slowest method of opening forms. However, it allows you to programmatically process the form before opening it. To process the code you need to change a little:

Form = GetForm( "Document. Receipt of Goods and Services. Document Form") ;
//Here we perform actions with the form
Form. Open();

It should be taken into account that when the form is received, another event procedure will be executed WhenCreatedOnServer.

Let's look at other methods that allow you to open forms in a managed 1C application faster and more conveniently. Depending on the specific situation, different methods may be used.

1. How to open an object form in a managed application if there is a link to it.

In this case, everything is extremely simple.

RefLink = Directories. Nomenclature. FindByCode("000000001" ) ;
OpenValue(RefLink) ;

2. How to open the selection form and then get the selected value.

There is a function for this EnterValue(). The function has 3 parameters:

  • The variable into which the selected value will be written;
  • A hint that will be displayed in the selection window;
  • Description of the types of selected values. There may be several types, in which case you will be prompted to select a type before selecting a specific value.

As a result of executing the function, the default selection form for an object of the specified type will open.

Variable Value;
Array= new Array;
Array. Add(Type( "DirectoryLink.Nomenclature") ) ;
Array. Add(Type( "DirectoryLink. Counterparties") ) ;

TypeDescription= new TypeDescription(Array) ;

Res = EnterValue(Value, "Hint" , TypeDescription) ;

Previous methods only allowed you to open the default forms for objects (object form or selection form). If you need to open a custom form, you can use the function OpenForm().

This function has quite a few parameters. Let's look at some of them:

  • Form name— here you can select either one of the standard object shapes, for example, Selection Form or List Form. Or a specific form created by the developers.
  • Options— allows you to transfer it to the form in the form structures some parameters before opening it, thereby determining the output data. Parameters can be any data that can be passed from the client to the server. The parameters passed when opening the form can be processed in the procedure WhenCreatingOnServer() at the form being opened.
  • Form opening mode— has 3 options: independent, block the entire interface, block the owner form.

Let's look at how the function is used OpenForm() in various situations.

3. How to open the form of an existing object

Each form has one key attribute. It is highlighted in bold in the list of form details and is usually called An object in the forms of elements of reference books and documents. Other objects may have a different name. To open a form of an existing object, you need to pass a parameter to the form being opened Key with the value as a reference to an object.

&OnClient
Procedure Command1 (Command)
Parameter= new struct;
Parameter. Insert("Key" , FindC() ) ;
OpenForm(, Parameter) ;
End of Procedure

&On server
Function FindC();
Return Directories. Counterparties. FindByRequisites ("TIN", "745107734623")
EndFunction

4. How to open a new object form

A simple function will do here OpenForm() without any parameters.

&OnClient
Procedure Command1 (Command)
OpenForm( "Directory. Counterparties. Object Form") ;
End of Procedure

5. How to open a new object form and fill it out based on something

You need to pass a parameter Base, the value of which will be a reference to the filling base object. This will start the procedure ProcessFill().

&OnClient
Procedure Command1 (Command)
Parameter= new struct;
Parameter. Insert("Base", LinkToBuyerAccount) ;
OpenForm( "Document. Sales of Goods and Services. Object Form", Parameter) ;
End of Procedure

This example will create a document Sales of goods and services and filled out on the basis of an invoice for payment to the buyer, the link to which was transmitted.

6. How to open a form and set a selection on it

Selection on 1C forms can be simple or complex. Simple selection involves expressions like Organization = Horns and Hooves LLC. Complex selection involves other types of comparison, e.g. On the list. In this article we will consider the organization of simple selection, and a separate article will be devoted to complex selection.

To organize a simple selection, you need to pass a parameter with a key to the form being opened Selection, the value will be a structure in which the key is the name of the dynamic list field, and the value is the data being sought.

For example, let's open the directory list form GTD numbers and make a selection there by owner - directory element Nomenclature.

&OnClient
Procedure Command1 (Command)
Parameter= new struct;

Selection= new Structure;
Selection. Insert("Owner", LinkToNomenclature) ;

Parameter. Insert("Selection", Selection) ;

OpenForm( "Directory.GTD numbers.List form", Parameter) ;
End of Procedure

7. How to open the information register entry form

To do this, you will need the information register entry key.

Record Key— these are the values ​​of all measurements and the period (if the register is periodic). That is, a record key is the parameters by which a record can be uniquely identified.

The opening algorithm is as follows:

  1. We enter the record key data with the necessary values ​​into the structure.
  2. We place the resulting structure in an array.
  3. We create a record key from the array.
  4. We pass a parameter to the form that opens Key with the record key from step 3 as the value.

&OnClient
Procedure Command1 (Command)
Parameter= new struct;

KeyParameters= new Structure;
Key parameters. Insert("Nomenclature", LinkToNomenclature) ;
Key parameters. Insert("PriceType", LinkToPriceType) ;
Key parameters. Insert("Period", Date) ;

KeyArray = New Array;
KeyArray. Add(KeyParameters) ;

EntryKey = New( "Information RegisterRecord Key.PricesNomenclature", KeyArray) ;

Parameter. Insert("Key", RecordKey) ;

OpenForm( "Register of Information. Prices of Nomenclature. Record Form", Parameter) ;
End of Procedure

home For beginner developers Learn to program

How to open a form of an existing object?

When opening a form of an existing object, in addition to the name of the form, you must also indicate the object whose form should be opened. To do this, use the Key form parameter and a link to the object of interest to us.

For example, if from the list of organizations form you need to open the form of the organization on which the cursor is located, you can do this in the following way:

We pass form parameters in the form of a structure, where the name of the structure element corresponds to the name of the form parameter, and the value is the value to which we want to set the form parameter.

If you want to open not the main, but an arbitrary form of an object created in the configurator, instead of the standard name of the main form (ObjectForm), indicate the word Form followed by a dot - the name of the form created in the configurator.

For example:

ReferenceToDirectoryElement = Elements.List.CurrentRow; FormParameters = New Structure("Key", ReferenceToDirectoryElement); OpenForm("Directory.Organizations.Form.UniversalObjectForm",FormParameters);

It should be noted that in the case when, in addition to a link to an object, no parameters need to be passed to the form being opened and it is the main form of the existing object that is needed, you can use a simpler method - open the form using the procedure OpenValue():

OpenValue(Items.List.CurrentRow);

This method is less versatile, but in some cases it saves time and effort. For example, in the case considered, one such line can replace the entire three-line procedure we wrote earlier.

However, care must be taken when using this procedure. In some cases, it may cause additional calls to the server, for example, when you need to open a hierarchical directory item form. When using this procedure, the platform will make an additional call to the server to determine whether an element is a group or not, since different forms must be opened for the element and for the group.

At the same time, this information can be known in advance to the developer within his algorithm, and, using the OpenForm() function, the developer can open the desired form without additional calls to the server, immediately specifying the standard name of the main form.

Good day everyone!
I think that the information in this topic will be very useful to many visitors to this forum.
For a long time I could not solve the problem - how to open the form of a new document so that it opens not empty, but already partially filled out programmatically, while the document itself has not yet been recorded in the database? I spent a lot of time searching for a solution to this problem on the Internet, visited many forums where this issue was raised, but only a few of them came across solutions. The simplest of them is to first programmatically create a new document, programmatically fill in the necessary details, write the document to the database, and then open it to the user. What if the user doesn't want to save it? What if he changes his mind and closes the open form? In this case, the already recorded document will remain in the database. And who needs extra documents in the database?
And if you don’t save the document, then the most popular option is to use the GetForm method (“Documents. Required Document Type. Document Form”). But in this case, you can get an empty document form and simply display it using the Open() method. This is also not an option...
After some time, the problem was solved using the global context function “Fill in Property Values.”

Global context
FillPropertyValues
Syntax:
Fill PropertyValues(<Приемник>, <Источник>, <Список свойств>, <Исключая свойства>)
Description:
Copies property values<Источника>to properties<Приемника>. Matching is done by property names.

Using my task as an example, I would like to explain how you can use this function to fill out a form for a new document. The task was as follows: There is one document (Work Order), the requisite of the tabular part of which is another document (Provision of services). So, it was necessary to make sure that when a new document “Rendering of Services” was added to the tabular part of the “Work Order”, the form of the new document “Rendering of Services” was displayed on the screen with the details already filled in, taken from the work order from which creation was caused. At the same time, the new document itself, at the time its form appears on the screen, has not yet been recorded in the database. This had to be done if the user suddenly decides not to fill out the document and simply closes the form.
Here is a code fragment with a solution to the problem:

&On the Client Procedure EnterRecord()RecordForm = GetForm("Document.Provision of Medical Services.ObjectForm"); Fill inPropertyValues(RecordForm.Object,Object,"Date,Specialist,Specialization,Nurse,Execution Status",); // Fill in the values ​​of details whose names are the same in both documents TextStr = Elements.Reception.CurrentData; //Data of the current line of the source documentProperty Structure = New Structure; // The structure contains the values ​​of those details that need to be filled in on the form of the new document, but which are not in the source document StructureProperties.Insert("Work Order", Object.Link); PropertyStructure.Insert("ReceptionTime",TexStr.ReceptionTime); Fill inPropertyValues(RecordForm.Object,PropertyStructure,"RecordOrder,AppointmentTime",); EntryForm.Open(); End of Procedure

That is, we perform all operations directly on the client, without contacting the server, within one independently created procedure. In fact, in this way you can fill out and open the form of any document or reference book. First, I filled in the details from one form to another using form objects, and then, using the “Structure” object, into which I inserted the missing details, I filled in some more details of the form being opened, and then opened the form.
I hope that this topic will save time for many who are faced with a similar task!