Home / Setting / 1c pass parameters to the selection form. Passing parameters to managed and regular forms. How to open a select form and then get the selected value

1c pass parameters to the selection form. Passing parameters to managed and regular forms. How to open a select form and then get the selected value

Print (Ctrl+P)

Form Options

1. General information

Form parameters (tab Parameters) serve two purposes:
● Describe the set of data that will affect the opening of the form (form parametrization). To do this, you need to list all the necessary parameters and specify their types.
● Define the parameters that will affect the shape uniqueness key. To do this, you need to set the property Key parameter those parameters that should participate in the formation of the form uniqueness key. When you try to open a form, the system searches for an existing form using the generated form uniqueness key. If there is a form with the received key in the system
uniqueness, this form is returned; if not, a new form is created.
When a form is invoked, developer-created parameter values ​​can be specified in the parameter structure, along with form system parameters (if any).
Form parameters can be passed to the form at the time of its creation. The analysis of the passed parameters can be performed in the event OnCreateOnServer() (the Parameters collection is a property of the object ManagedForm):

// At the call site.
// Form the form parameter.
Parameters = New Struct();
Options.Paste("Importance", PredefinedValue(“Enumeration.Importance.Important”));
// Open the form with parameters.
OpenForm("GeneralForm.ViewForm", Parameters);

// In the form module.
&On server
Procedure OnCreateOnServer(Failure, StandardProcessing)
If Parameters.Importance = Enums.Importance.Important Oh Then

EndIf;
EndProcedure

ATTENTION! After calling the event handler OnCreateOnServer all non-key form parameters are removed from the Parameters collection.
Advice. Non-key form parameters that are necessary for further work must be stored in the form data.

2. Standard form options

In order to support automatic interaction between forms, the system provides a number of standard options that are used to control forms when they are opened. With the help of these parameters, the system implements in the form fields the selection from the selection forms, the opening of object forms, the operation of standard commands, etc. That is, they provide various interface operation scenarios embedded in the system.
But the developer can also use these parameters in the 1C:Enterprise language by passing them when calling the OpenForm() method.
The list of standard form parameters depending on the type of form extension can be found in the sections Embedded Language - Interface
(managed) - Managed form - Extension...inline references.

3. An example of working with form parameters

To demonstrate how the form parameters work, let's consider the implementation of selecting an element in the input field. The essence of the example will be the implementation of the mechanism for selecting an element from the list in the built-in language.
By the time you start working with the example, you need to have a configuration that has the following properties:
● there is a Goods directory with a hierarchy of groups and elements;
● there is a directory Analogues with the attribute SelectedProduct of type DirectoryLink.Products;
● Both reference books have item forms.
Now we implement in this configuration all the mechanisms that the platform uses to select an element from the list, in the built-in language. In doing so, we will see:
● how standard form parameters are used;
● how the system uses them;
● how a developer can use them.
Let's add additional parameter An that will control the closing of the select form after an item is selected. Let's call this parameter CloseAfterSelection(boolean type). Let's add it as a parameter of the form Selection form of the Goods directory.
In order to open the element selection form, it is necessary to create an event handler for the SelectStart event at the SelectedItem form element in the form of the Analogues directory element.

&AtClient
Procedure SelectedItemSelectionStart(Item, StandardProcessing)
Standard Processing= false ;
Choice Options= New Structure ;
SelectionParameters.Insert(“SelectionMode”, True);
SelectionParameters.Insert(“SelectGroupsAndItems”, UsingGroupsAndItems.Items);
SelectionParameters.Insert(“AllowRootSelection”, False);
SelectionParameters.Insert(“CurrentLine”, Object.SelectedItem);
SelectionParameters.Insert(“CloseAfterSelection”, False);
OpenForm(“Catalog.Products.ChoiceForm”, Choice Options, Items.SelectedProduct);
EndProcedure
We should dwell separately on the third parameter of the OpenForm() method. This parameter determines who will be the owner of the selection form and who will be notified of the selection made. IN this case we have specified the form element itself as the owner of the selection form, but we can also specify the form itself with this parameter. In this case, it will be necessary to implement the handler HandlingChoice form module and decide in it which form attribute to place the selected data in.
NOTE. If we do not implement the event handler StartChoice , then the system itself will perform its actions. This is true for all further handlers that are used in the example.
Now we need to process the passed parameters in the select form. Let's do it in the handler OnCreateOnServer() of the select form module.

&On server
Procedure OnCreateOnServer(Failure, StandardProcessing)
Standard Processing= false ;
Elements.List.SelectGroupsAndItems = Parameters.SelectGroupsAndItems;
Elements.List.AllowSelectRoot = Parameters.AllowSelectRoot;
Items.List.CurrentRow = Parameters.CurrentRow;
CloseOnSelection = Parameters.CloseAfterSelection;
EndProcedure
In order to check the performance of the form parameters set by us, we will set, using the configurator, the List property of the selection form table SelectGroupsAndItems to the Groups value (without applying the parameter, the selection of dictionary elements will not be available).
NOTE. If the List table, which displays a list of products, does not have the SelectionMode property set to True , then the selection of products will not be available.
Now we need to handle the selection of the desired item in the selection form. To do this, you need to define an event handler for the SelectValues ​​event of the form table.

&AtClient
Procedure ListSelectionValues(Item, StandardProcessing, Value)
Standard Processing= false ;
NotifySelection(Value);
EndProcedure
It remains for us to implement the processing of selecting an element in the input field itself. To do this, you need to handle the event HandlingChoice our input field SelectedProduct.

&AtClient
Procedure SelectedItemProcessingChoice(Item, SelectedValue, StandardProcessing)
Standard Processing= false ;
Object.SelectedItem = SelectedValue;
EndProcedure
We independently implemented a system mechanism for selecting a value in the input field on the form.
ATTENTION! This example is not complete. Its sole purpose is to demonstrate the mechanics of working with form parameters.
If when creating parameters (handler SelectedItemSelectionStart()) replace the line:

SelectionParameters.Insert(“CloseAfterSelection”, True );
to the line:
SelectionParameters.Insert(“CloseAfterSelection”, False) ;
then the selection form will stop closing after the selection is made. This can be used, for example, to implement a selection form (selecting multiple products without closing the selection form).

In order to support automatic interaction between forms, the system provides a number of standard options that are used to control forms when they are opened. With the help of these parameters, the system implements in the form fields the selection from the selection forms, the opening of object forms, the operation of standard commands, etc. That is, they provide various interface operation scenarios embedded in the system. But the developer can also use these parameters in the 1C:Enterprise language by passing them when calling the OpenForm() method.

We list the parameters provided by the system and their purpose:

  • Selection Mode– the form opens in selection mode. Provided by extension managed form dynamic list.
  • CurrentLine– a string that will be activated in the list when opened. A value is passed that identifies the string. Provided by the dynamic list managed form extension.
  • SelectGroupsAndItems– this parameter sets the SelectGroupAndItems property of the table of the main attribute of the form. Provided by the dynamic list managed form extension.
  • AllowSelectionRoot– determines whether the root can be selected in the form with a dynamic list displayed as a tree. Provided by the managed form extension of a dynamic list displayed as a tree.
  • Selection– selection set in a dynamic list. Represents a structure. The names of the elements correspond to the names of the fields by which the selection is made, and the values ​​contain the values ​​of the selection. Provided by the dynamic list managed form extension.
  • Key– value identifying the object being edited in the form. If the value is missing or incorrect, a new object is created using the remaining parameters. Provided by object forms and information register record manager extensions.
  • ValueCopy– a value identifying the object that will be used for copying when creating a new object. Provided by object forms and information register record manager extensions.
  • Fill Values– values ​​for filling in the details of the new object. Represents a structure. The names of the elements correspond to the names of the attributes, and the values ​​contain the data that will be used to fill in the specified attributes. Provided by object forms and information register record manager extensions.
  • Base– a value identifying the object that will be used as the basis when creating a new object by input on the basis. Provided by object form extensions.
  • This group– defines the type of the new object: group or element. Provided by object form extensions.

Example of working with form parameters

To demonstrate how the form parameters work, let's consider the implementation of selecting an element in the input field. The essence of the example will be the implementation of the mechanism for selecting an element from the list in the built-in language.

By the time you start working with the example, you need to have a configuration that has the following properties:

  • The main launch mode is Managed Application;
  • there is a Goods directory with a hierarchy of groups and elements;
  • there is a directory Analogues with the attribute SelectedItem of the DirectoryReference.Goods type;
  • both reference books have managed item forms.

Now we implement in this configuration all the mechanisms that the platform uses to select an element from the list, in the built-in language. In doing so, we will see how the standard form parameters are used; how the system itself uses them; how a developer can use them.

Let's add an additional flag that will control the closing of the selection form after an element is selected. Let's call this flag CloseAfterSelection (Boolean type). Let's add it as a form parameter of the Goods directory Selection Form.

In order to open the element selection form, it is necessary to create an event handler for the SelectStart event for the SelectedItem form element in the Analogues catalog element form:

&AtClient

Procedure SelectedItemSelectionStart(Item, StandardProcessing)

StandardProcessing = False;

ChoiceParameters = New Struct; SelectionParameters.Insert("SelectionMode", True); SelectionParameters.Insert("SelectGroupsAndItems", UseGroupsAndItems.Elements); SelectionParameters.Insert("AllowRootSelection", False); ChoiceParameters.Insert("CurrentRow", Object.SelectedItem); SelectionParameters.Insert("CloseAfterSelection", False); OpenForm("Catalog.Products.ChoiceForm", ChoiceParameters, Elements.SelectedProduct);

EndProcedure

We should dwell separately on the third parameter of the OpenForm() method. This parameter determines who will be the owner of the selection form and who will be notified of the selection made. In this case, we specified the form element itself as the owner of the selection form, but we can also specify the form itself with this parameter. In this case, it will be necessary to implement the SelectProcess handler of the form module and decide in it which form attribute to place the selected data in.

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.
  • Parameters- 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

This article describes how to pass a value as a parameter as a parameter when opening a managed form 8.2 in comparison with how a similar operation could be implemented in regular forms.

How parameters are passed in normal forms

In normal forms, there were 2 possibilities for passing a parameter:
1) a less common method: in the form of an object on the "Details" tab, the details were added, if necessary, access was determined by visual means
2) a more common way: an export variable was declared in the form module and the value was processed in the “BeforeOpening” handler

in both cases, the form call looked something like this:

Form = Object.GetForm("ChoiceForm",FormOwner,UniqueKey);
Form.Parameter = ParameterValue;
Form.Open();

How parameters are passed in managed forms

Managed forms now have the ability to immediately pass parameters when the form is received. Parameters are passed as a structure:

Parameters = New Structure("CurrentValue",LastItem);
ChoiceForm = GetForm("Catalog.Nomenclature.ChoiceForm",Parameters);
FoundItem = ChoiceForm.OpenModal();

Also, the managed form has "form extensions" (object, directory, document, report). Depending on the object type, the list of available parameters is determined. For example, if you need to position on a certain element in the dictionary selection form, then the “CurrentValue” parameter is used. The big plus is that in the form itself it is not required to write handlers for predefined parameters, which reduces the amount of code.

Also, the developer has the opportunity to define their own parameters (in the designer of the managed form, the "Parameters" tab). The lifetime of the parameters is limited by the OnCreateOnServer handler, which is logical because parameters are required only when creating the form, but if this parameter determines the uniqueness of the form (the "key parameter" flag is set in the parameter properties), it will be available in other handlers.

To pass a specific manipulation parameter, you need to do a bit more:

1) Define a parameter in a managed form.
In the OnCreateAtServer handler, define the processing of this parameter (accessing the passed parameters through the “Parameters” property of the FormDataStructure type)
2) Describe the receipt of the form and pass the value of the new parameter in the parameters of the GetForm function.
So the code will look like:
- At the place of receipt of the form

Parameters = New Structure("NewParameter",LastElement);
ChoiceForm = GetForm("Catalog.Nomenclature.ChoiceForm",Parameters);

In a managed form module

&On server
Procedure On CreationOnServer(Failure, StandardProcessing)
If Parameters.Property("NewParameter") Then
// parameter processing code here
EndIf;
EndProcedure

Conclusion

Perhaps this article will be useful to someone, it saves time and saves you from unnecessary code. For more detailed information about complete list parameters of a managed form, it is recommended to look at the "Managed interface \ Managed form" help.

[you need to register to view the link]