In Designer mode

Let us implement opening the list with a filter.

  1. Open the list form of the Services document.
  2. In the form editor, add the following form attributes:
    • ScriptFilter. Type: Boolean.
    • FilterField. Type: Arbitrary.
    • FilterValue. Type: Arbitrary.
    These attributes will store the script filter data in the list form.
  3. Create the OnCreateAtServer event handler and fill it as shown in listing 27.8.

    Listing 27.8. OnCreateAtServer event handler

    &AtServer
    Procedure OnCreateAtServer(Cancel, StandardProcessing)
            
        If Parameters.Filter.Property("Technician") Then
            ScriptFilter = True;
            FilterField = New DataCompositionField("Technician");
            Parameters.Filter.Property("Technician",FilterValue);
        EndIf
     
    EndProcedure
    During the creation of the list form the procedure uses a collection of form parameters to check whether a filter by Technician field is set. If the filter is set, the procedure sets the flag showing that the form is opened using a script filter, sets FilterField to Technician data composition field, and assigns the appropriate filter value from the collection of form parameters to FilterValue.
  4. Create the OnOpen form event handler and fill it as shown in listing 27.9.

    Listing 27.9. OnOpen event handler

    &AtClient
    Procedure OnOpen(Cancel)
     
        If ScriptFilter = True Then
            ScriptSettings = List.SettingsComposer.FixedSettings;
            For Each SettingsItem In ScriptSettings.Filter.Items Do         
                If SettingsItem.LeftValue = FilterField Then             
                    ScriptSettings.Filter.Items.Delete(SettingsItem);
                EndIf;
            EndDo;
     
            Settings = List.SettingsComposer.Settings;
     
            FilterItem = Settings.Filter.Items.Add(Type("DataCompositionFilterItem"));
            FilterItem.LeftValue = FilterField;
            FilterItem.ComparisonType = DataCompositionComparisonType.Equal;
            FilterItem.RightValue = FilterValue;
     
            List.SettingsComposer.LoadSettings(Settings);
        EndIf;
     
    EndProcedure
    The handler script is executed if the form is opened with the script filter.

    First the procedure iterates through the collection of filter items of the fixed settings of dynamic list settings composer. If the collection includes a filter item where LeftValue is equal to the FilterField attribute value (a script filter by Technician field), this item is deleted.

    Then this filter is added to the dynamic list settings collection (SettingsComposer.Settings.Filter) and the modified settings are loaded to the settings composer.

    The only thing left is to delete the created filter item when the Services document list form is closed.
  5. Create the OnClose form event handler and fill it as shown in listing 27.10.

    Listing 27.10. OnClose event handler

    &AtClient
    Procedure OnClose(Cancel, StandardProcessing)
     
        If ScriptFilter = True Then
            Settings = List.SettingsComposer.Settings;
            For Each SettingsItem In Settings.Filter.Items Do
                If SettingsItem.LeftValue = FilterField Then
                    Settings.Filter.Items.Delete(SettingsItem);
                EndIf;
            EndDo;
            List.SettingsComposer.LoadSettings(Settings);
        EndIf;
     
    EndProcedure

    The handler script is executed if the form is opened with the script filter.

    The procedure iterates through the collection of filter items of the settings of dynamic list settings composer (SettingsComposer.Settings.Filter). If the collection includes a filter item where LeftValue is equal to the FilterField attribute value, this item is deleted. Then the modified settings are loaded to the settings composer.

Next page: In 1C:Enterprise mode
Be the first to know tips & tricks on business application development!

A confirmation e-mail has been sent to the e-mail address you provided .

Click the link in the e-mail to confirm and activate the subscription.