How to open a list form with some selection?

There are several ways to open a list form with some pre-set selection. Let's look at them in order:

1. The first method is that when opening the form, you can set the Selection form parameter, and open the list form with this parameter. The Selection parameter represents the structure. The names of the elements correspond to the names of the fields by which the selection is made, and the values ​​contain the selection values. This is a managed form extension option dynamic list. That is, it exists for forms whose main attribute is the type attribute Dynamic List, such as list forms and selection forms.

When opening the form, selection will be made based on the specified field. For example, in the following example, a list of invoices is opened with selection by the Number field, equal to 333.

Selection Value = New Structure("Number", "333");

SelectionParameters = New Structure("Selection", SelectionValue);

OpenForm("Document. Receipt Invoice. List Form", Selection Options);

2. You can open a list form without parameters:

OpenForm("Document.Invoice.ListForm");

And then, in the event handler of the invoice list form When CreatedOnServer write code that creates a selection in a dynamic list, which is the main attribute of the form:

&On server

Procedure When CreatedOnServer(Failure, StandardProcessing)

Selection Element = List.Selection.Elements.Add(Type("DataComposition Selection Element"));

SelectionElement.LeftValue = NewDataCompositionField("Number");

SelectionElement.ComparisonView = DataCompositionComparisonView.More;

SelectionElement.Use = True;

SelectionElement.DisplayMode = ElementDisplayModeDataCompositionSettings.Inaccessible;

SelectionElement.RightValue = "000000001";

End of Procedure

Advantages this method The point is that the Comparison Type for the selection can be set not only Equal, as in the first case, but also More, Less, etc.

But this method also has a very significant drawback: with this selection, the form will always open. Wherever she was called from. Therefore, this form should not be designated as the main one. And if, nevertheless, it is the main one, then before installing the selection, it is necessary to provide some kind of analysis of where this form opens from. For example, analyzing form parameters.

3. Finally, the selection condition can be placed in a custom query that selects data for a dynamic list. For example, we need to open a list of invoices that contain the item highlighted in the item list.

To do this, in the form of a list of items, create a command and a corresponding button Receipt invoices.

Let's fill out the execution handler for this command as follows:

&OnClient

Procedure ReceiptInvoices(Command)

ListForm = GetForm("Document.Invoice.ListForm");

ListForm.FilterByProduct = Elements.List.CurrentRow;

ListForm.Open();

End of Procedure

In this handler, we receive the form for the list of invoices and pass the link to the current item in the item list to the FilterByProduct form parameter and open the form with this parameter.

Then we will create a document list form Purchase Invoice and create the FilterByProduct form attribute, which we will use as a form parameter when opening it. Now let's open the properties palette of the main attribute of the List form. Let's set the flag CustomRequest and in the line List setup click Open.

In the Request field, enter the following request text:

CHOOSE

Document Receipt Invoice. Number,

Document Receipt Invoice.Date

FROM

Document.ReceiptInvoice AS DocumentReceiptInvoice

WHERE

Document Receipt Invoice.Products.Product = &Product

In the request, we use the Item parameter, which will receive a link to the current line in the item list, contained in the FilterBy Item invoice list form parameter. To do this, in the OnOpen list form event handler, we will write code to set the value of the Product request parameter:

&OnClient

Opening Procedure (Failure)

List.Parameters.SetParameterValue("Product", FilterByProduct);

End of Procedure

Here List.Options is a list of dynamic list request parameters for the List attribute. The value of the Product parameter is set equal to the value of the FilterByProduct form parameter.

As a result, at the click of a button Receipt invoices in the form of a list of items, we will receive a list of only those invoices that contain the items highlighted in this moment in the nomenclature list.

A demo example for the 3rd option is located in the 1CITS/EXE/FAQ/OpenFormWithSelection.dt directory. The example was performed on platform version 8.2.9.356.

Selection on managed forms in 1C 8.3

The article will discuss options for installing selection in managed forms 1C 8.3. The selection for a dynamic list can be set statically or dynamically, in the user interface or configurator. We will consider all selection options below.

  • Setting selection in the configurator

Setting selection in user mode

A dynamic list, as opposed to a table or tree of values, is a more suitable solution for implementing forms containing any lists, because The dynamic list provides the widest range of tools for working with selection, field grouping, and sorting. This selection can be set when working in user mode or configurator, the principle is the same.

To set up selection in enterprise mode, you need to call the “Customize list” command.

A window will open.


The “selection” tab presents a list of fields that are in the current list. Select the list fields by which we will filter. This can be done by double clicking or using drag and drop.


We set the comparison type and value, click “Finish editing”, the selection is set.


When you set up selection in enterprise mode, so-called quick selection fields are automatically created on the list form.


In order for the 1C platform to automatically create quick selection fields, when developing a form in the configurator, you must specify a group of user settings.


This selection will only be saved for current user, which allows you to flexibly make customized settings for the dynamic list. However, if the task is to make a fixed selection for a specific list for all users of the system, we can only solve it through the configurator.

Setting selection in the configurator

Working in the configurator, we can set two types of dynamic list selection – fixed and dynamic. Fixed selection can be configured once, dynamic or programmatic can be set depending on any data in the system.

The principle of setting a fixed selection in the configurator is no different from setting it in the user mode described above. To set the selection, we must open the dynamic list settings.


A window will open.


Selection is set in the same way as in user mode.

The “Include in user settings” option determines whether the selection set in the configurator will be available in user mode through the “Customize list” menu item.


Dynamic (software) selection

Often there is a need to set selection programmatically, for example, when opening a selection form, when we need to open a controlled form with selection. A parameter is passed to the form and selection is set based on this parameter. A common example of this is selecting directory items by owner.

Methods

If the configuration being developed contains the BSP “Basic Functionality” subsystem, program selection in a dynamic list can be set using the standard method:

GeneralPurposeClientServer.SetDynamicListSelectionElement()

Signature of this method:

DynamicList Type: DynamicList – The list in which you want to set the selection.

FieldName Type: String – The field by which you want to set the selection.

RightValue Type: Arbitrary – Selection value (Optional. Default value: Undefined. Note: If you pass Undefined, the value will not be changed).

ViewComparison Type: DataComposition Comparison Type – Selection Condition.

Performance Type: String – Representation of a data composition element (Optional. Default value: Undefined. If specified, only the use flag with the specified representation is printed (no value is printed). An empty string must be passed to clear so that the value is printed again.)

Usage Type: Boolean – Flag to use this selection (Optional. Default: Undefined).

Display Mode Type: ItemDisplayModeDataCompositionSettings – How this selection is displayed to the user. Possible values:

  • Element Display ModeData Layout Settings.Quick Access – In Group quick settings above the list.
  • Element Display ModeData Layout Settings. Normal – In list settings (in the More submenu).
  • ElementDisplayModeDataCompositionSettings.Inaccessible – Prevent the user from changing this selection.

IdentifierUserSettings Type: String – Unique identifier for this selection (Used to communicate with user settings).

To remove a selection value, you must use the standard method:

General PurposeClientServer. RemoveGroupElementsSelectionDynamicList()

Signature of this method:

DynamicList Type: DynamicList – form attribute for which you want to set selection.

FieldName Type: String – name of the layout field (not used for groups).

Performance Type: String – Representation of a layout field.

If there is no BSP in the system, selection can be set independently using the DataComposition Field object.

Selection Element = List.Selection.Elements.Add(Type("DataComposition Selection Element")); Selection Element.LeftValue = NewDataCompositionField("Name"); Selection Element.Comparison Type = DataComposition Comparison Type.Equal; Selection Element.DisplayMode = ElementDisplayModeDataCompositionSettings.QuickAccess; // Optional Selection Element. RightValue = "Ivanov";

This selection will select rows in which the value “Full name” = “Ivanov”.

To use logical “AND”, “OR”, “NOT” the data type DataCompositionSelectionElementGroup is intended

Selection Group = List.Selection.Elements.Add(Type("Group of DataComposition Selection Elements")); SelectionGroup.GroupType = DataCompositionSelectionElementGroupType.GroupOR; Selection Element = Selection Group. Elements. Add(Type("Data Composition Selection Element")); Selection Element.LeftValue = NewDataCompositionField("Name"); Selection Element.Comparison Type = DataComposition Comparison Type.Equal; Selection Element.RightValue = "Ivanov"; Selection Element = Selection Group. Elements. Add(Type("Data Composition Selection Element")); Selection Element.LeftValue = NewDataCompositionField("Name"); Selection Element.Comparison Type = DataComposition Comparison Type.Equal; SelectionElement.RightValue = "Petrov";

This selection will select rows in which the value “Full name” = “Ivanov” or “Petrov”.

Selection in a dynamic list can also be done by changing the text of the dynamic list request. This option works when the dynamic list is made via a "custom request".


To do this, add the condition “WHERE IS THE TRUE” to the query text...


As you can see, this approach is more compact in terms of writing code. How more difficult conditions we want to establish selection in the tabular part, the more cumbersome the option using selection through the Data Composition Selection Element will be. However, the example with changing the request text has its drawbacks - this implementation is not resistant to code changes. For example, you made such an implementation and forgot, but if in the future you want to modify the request text by adding some operator after WHERE (ORDER, GROUP), you need to remember that the program code contains:

List.QueryText = List.QueryText + " And DirectoryUsers.Full Name V(""Ivanov"",""Petrov"")";

If this is not taken into account, there will be an error, but to avoid this, you can change it to a different implementation. We add the following condition to the request text:

WHERE (NOT &SelectionInstalled OR DirectoryUsers.Name IN (&PermittedName))

List.Parameters.SetParameterValue("SelectionSet", Full Name.Quantity() > 0); List.Parameters.SetParameterValue("Allowed Full Name", Full Name);

Here full name is an array.

As you can see, 2 lines of code versus 10. Which method to choose depends on the specific application task.

This code allows you to open a list of documents with a specified selection; you can also open a list of directory elements with the desired selection

Code 1C v 8.2 UP Form = OpenForm("Document. Invoice.Form.ListForm"); //Open the form
SelectionOwner =Form.List.Selection.Elements.Add(Type("DataCompositionSelectionElement")); //Add selection
SelectionOwner.ComparisonView = DataCompositionComparisonView.Equals; //How will we compare
SelectOwner.Use = True; // Set the checkbox for using NewDataCompositionField("Nomenclature")
SelectionOwner.LeftValue = NewDataCompositionField("Account"); //What details will we use to make the selection?
SelectionOwner.RightValue = Object.Account; // And the very meaning of selection

In order to open a list form with a predefined selection use the following methods:

First way is that when you open a form, you can set the Selection form parameter and open the list form with this parameter.

The Selection parameter represents the structure. The names of the elements correspond to the names of the fields by which the selection is made, and the values ​​contain the selection values. This is a dynamic list managed form extension option. That is, it exists for forms whose main attribute is an attribute of the DynamicList type, for example, list forms and selection forms.

For example, in the following example, a list of invoices is opened with selection by the Number field, equal to 333.

Code 1C v 8.2 UE Selection Value = New Structure("Number", "333");
SelectionParameters = New Structure("Selection", SelectionValue);
OpenForm("Document. Receipt Invoice. List Form", Selection Options);

Second way

You can open a list form without parameters:

Code 1C v 8.2 UE OpenForm("Document. Receipt Invoice.List Form");

And then, in the event handler of the form for the list of invoices When CreatedOnServer, write code that creates a selection in the dynamic list, which is the main attribute of the form:

Code 1C v 8.2 UP &OnServer
Procedure When CreatedOnServer(Failure, StandardProcessing)
Selection Element = List.Selection.Elements.Add(Type("DataComposition Selection Element"));
SelectionElement.LeftValue = NewDataCompositionField("Number");
SelectionElement.ComparisonView = DataCompositionComparisonView.More;
SelectionElement.Use = True;
SelectionElement.DisplayMode = ElementDisplayModeDataCompositionSettings.Inaccessible;
SelectionElement.RightValue = "000000001";
End of Procedure

The advantages of this method are that the Comparison Type for the selection can be set not only to Equal, as in the first case, but also to More, Less, etc.

But this method also has a very significant drawback: with this selection, the form will always open. Wherever she was called from. Therefore, this form should not be designated as the main one. And if, nevertheless, it is the main one, then before installing the selection it is necessary to provide some kind of analysis of where this form opens from. For example, analyzing form parameters.

Third way

Finally, the selection condition can be placed in a custom query that selects data for a dynamic list.

For example, we need to open a list of invoices that contain the item highlighted in the item list.

To do this, in the form of a list of items, create a command and the corresponding button Receipt invoices.

Let's fill out the execution handler for this command as follows:

Code 1C v 8.2 UP &OnClient
Procedure ReceiptInvoices(Command)
SelectionParameters = New Structure("FilterByProduct", Elements.List.CurrentRow);
OpenForm("Document. Receipt Invoice. List Form", Selection Options);
End of Procedure

In this handler, we open the form for the list of invoices, passing a link to the current item in the item list to the FilterByProduct form parameter.

Then we will create a form for the list of documents: Receipt Invoice and create a FilterBy Product form parameter, which we will use to open a form with the required selection.

Now let's open the properties palette of the main attribute of the List form. Set the Custom Query flag and in the List Settings line click Open.

In the Request field, enter the following request text:

Code 1C v 8.2 UP SELECT
Document Receipt Invoice. Number,
Document Receipt Invoice.Date
FROM
Document.ReceiptInvoice AS DocumentReceiptInvoice
WHERE
Document Receipt Invoice.Products.Product = &Product

In the request, we use the Item parameter, which will receive a link to the current line in the item list, contained in the FilterBy Item invoice list form parameter.

To do this, in the list form event handler When CreatedOnServer, we will write code to set the value of the Product request parameter:

Code 1C v 8.2 UP &OnClient
Opening Procedure (Failure)
List.Parameters.SetParameterValue("Product", Parameters.FilterByProduct);
End of Procedure

Here List.Parameters is a list of dynamic list request parameters for the List attribute. The value of the Product parameter is set equal to the value of the FilterByProduct form parameter.

As a result, by clicking the Receipt invoices button in the item list form, we will receive a list of only those invoices that contain the item currently selected in the item list.

In order to open the selection form with selection in 1s 8.2(regular forms), we need to perform some actions. We'll get it first. After that, we’ll set the selection and open it programmatically, here’s a code example:

Selection on the form in the 1C 8.2 input field with several values

In the example above we looked at how to set selection on the selection form by specific value. Now let's look at a situation where you need to substitute several values, this could be, for example, an array or unloaded from a query result. This is a selection in the 1c input field with multiple meanings.

First, we get the selection form, pass “Element” (owner) in the parameters, set the selection mode flag. Then we create a list of values ​​and an array, we note that as a selection when setting the type of comparison in the list, an object can only be present with the type ListValues. We add elements to the array, then load this array into the List of Values, which we subsequently set in the selection. Also, don’t forget to enable the flag for using this selection and set the Comparison Type.

Setting selection in the input field on the form in 1C 8.3, Start of Selection event

Now let's consider selection in the input field on in a manageable form in 1C 8.3. Let’s find on the form the element we are interested in, in which we will set the selection, in our case this is the “Organization” field. We find the “Start of Selection” event, click on the magnifying glass and find ourselves in the procedure. We see the Selection Data parameter; this parameter is of the ValueList type. In order to limit the selection to the necessary elements, we need to fill in the List of Values. We can select elements only on the server, so we create a procedure with the &OnServer compilation directive. In this procedure, fill in the Selection Data.