How to set up smartphones and PCs. Informational portal
  • home
  • Internet, Wi-Fi, local networks
  • 1c programmatically open a document. How to open the form of an existing object? How to open a select form and then get the selected value

1c programmatically open a document. How to open the form of an existing object? How to open a select form and then get the selected value

Home For Beginner Developers Learn to Program

How to open the form of an existing object?

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

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

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

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

For example:

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

It should be noted that in the case when, in addition to a reference 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 has less versatility, but in some cases it saves time and effort. For example, in the considered case, 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 the form of a hierarchical directory element. When using this procedure, the framework will make an additional round trip to the server to determine if the element is a group or not, since different forms need to be opened for the element and for the group.

At the same time, this information can be known to the developer in advance within his algorithm, and using the OpenForm() function, the developer can open the required 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 written to the database? I spent a lot of time searching for a solution to this problem on the Internet, I 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 do not save the document, then the most popular option is to use the GetForm("Documents.DesiredDocumentType.DocumentForm") method. But in this case, you can get an empty form of the document and simply display it using the Open() method. This is also not an option...
After some time, the task was solved using the function of the global context "FillPropertyValues".

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

Using the example of my task, I would like to explain how you can use this function to fill out the form of a new document. The task was as follows - There is one document (Order-order), the requisite of the tabular part of which is another document (Provision of services). So, it was necessary to make it so that when adding a new document “Provision of services” to the tabular part of the “Order-order”, the form of the new document “Provision of services” was displayed on the screen with the details already filled in, taken from the order-order from which creation was called. At the same time, so that the new document itself, at the time its form appears on the screen, has not yet been written to 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 snippet with a solution to the problem:

&On the Client Procedure EnterRecord() RecordForm = GetForm("Document.MedicalServices.ObjectForm"); Fill inPropertyValues(Record Form.Object,Object,"Date,Specialist,Specialization,Nurse,Execution Status",); // Fill in the values ​​of the attributes whose names are the same in both documents TekStr = Elements.Receive.CurrentData; //Data of the current line of the source document StructureProperty = New Structure; // The structure contains the values ​​of those details that need to be filled in on the form of a new document, but which are not in the source document. StructureProperties.Insert("OutfitRecord",Object.Link); StructureProperty.Insert("Reception Time", CurrentStr. Reception Time); Fill inPropertyValues(RecordForm.Object,PropertyStructure,"OutfitRecord,ReceptionTime",); RecordForm.Open(); EndProcedure

That is, we do all operations directly on the client, without contacting the server, within one self-created procedure. In fact, in this way you can fill out and open the form of any document or directory. 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, filled in some more details of the opened form, and then opened the form.
I hope this thread will save time for many who are faced with a similar task!

Opening forms programmatically in a managed 1C application is significantly different from opening them in a regular application. Let's start with the old method. It consists in receiving the form and its subsequent opening 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. For processing, the code needs to be slightly modified:

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

It should be borne in mind that when the form is received, another event procedure will be performed OnCreateOnServer.

Consider other methods that allow you to open forms in a managed 1C application faster and more conveniently. Different methods may be used depending on the specific situation.

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

In this case, everything is extremely simple.

RefReference= References. Nomenclature. FindByCode("000000001" ) ;
OpenValue(ReferenceReference) ;

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

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

  • The variable in which the selected value will be written;
  • The hint that will be displayed in the selection box;
  • Description of the types of selected values. There can be several types, then before choosing a specific value, you will be prompted to select a type.

As a result of the function execution, the default selection form for the 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) ;

The previous methods allowed opening only the forms set for objects by default (object form or selection form). If you need to open an arbitrary form, you can use the function OpenForm().

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

  • Form name- here you can select either one of the standard forms of the object, for example, FormSelect or FormList. Or a specific form created by the developers.
  • Options- allows you to transfer 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 OnCreateOnServer() on the opened form.
  • Form opening mode- has 3 options: independent, block the entire interface, block the owner form.

Let's see 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 attributes and is usually called An object at forms of elements of directories, documents. Other objects may have a different name. To open the form of an existing object, you need to pass the parameter to the opened form Key with value as an object reference.

&AtClient
Procedure Command1 (Command)
Parameter= new struct;
Parameter. Insert("Key" , FindC() ) ;
OpenForm(, Parameter) ;
EndProcedure

&On server
FindC() function;
Return Handbooks. Counterparties. FindByAttribute ("TIN", "745107734623" )
EndFunctions

4. How to open the form of a new object

This is just a function OpenForm() without any parameters.

&AtClient
Procedure Command1 (Command)
OpenForm( "Reference book. Counterparties. Object form") ;
EndProcedure

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

Need to pass a parameter Base, whose value will be a reference to the fill base object. This will start the procedure HandleFill().

&AtClient
Procedure Command1 (Command)
Parameter= new struct;
Parameter. Insert("Reason" , LinkToAccountToBuyer) ;
OpenForm( "Document. Realization of Goods and Services. Object Form", Parameter) ;
EndProcedure

This example will create a document Sale of goods and services and completed on the basis of the invoice for payment to the buyer, the link to which was transferred.

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

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

To organize a simple selection, you need to pass a parameter with the key to the opened form 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 to be searched.

For example, let's open the lookup list form Non-GTE and we will make a selection there by the owner - the element of the directory Nomenclature.

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

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

Parameter. Insert("Selection", Selection) ;

OpenForm( "Directory.GTE Numbers.List Form", Parameter) ;
EndProcedure

7. How to open the information register entry form

To do this, you need a record key of the information register.

Record key are the values ​​of all measurements and the period (if the register is periodic). That is, the key of the record is the parameters by which the 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. From the array we create the record key.
  4. Passing a parameter to the opened form Key with the record key from item 3 as the value.

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

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

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

RecordKey = New( "Information RegisterRecordKey.NomenclaturePrices", ArrayKey) ;

Parameter. Insert("Key", RecordKey) ;

OpenForm( "Information Register. Nomenclature Prices. Record Form", Parameter) ;
EndProcedure

Top Related Articles