Creatio development guide
This documentation is valid for Creatio version 7.14.0. We recommend using the newest version of Creatio documentation.

Handling the selection of several records. Examples

Glossary Item Box

Introduction

Before you start implementing cases it is recommended to study the "How to add a section action: handling the selection of several records” article.

Example

Case description

Implement action for the [Activities] section list that will set the [Completed] status for several selected list activities.

Source code

You can download the package with case implementation using the following link.

Case implementation algorithm

1. Create a replacing page of the [Activities] section in the custom package

The procedure for creating a replacing page is described in the“Creating a custom client module schema” article.

2. Add a string with the [Actions] menu title to the localized string collection of the section replacing schema

Populate the following values for the created string (Fig.1):

  • [Name] – "AllDoneCaption";
  • [Value] – "Mark as "Completed"”.

Fig. 1. Properties of the custom localizable string

3. Add the implementation of the following methods to the method collection of the section view model

  • isCustomActionEnabled() – the method that determines if the added menu option is enabled.
  • setAllDone() – the action handler method that sets the [Completed] status for several selected list activities.
  • getSectionActions() – an overridden parent schema method that gets the section action collection.

The replacing schema source code is as follows:

define("ActivitySectionV2", ["ConfigurationConstants"],
    function(ConfigurationConstants) {
        return {
            // Section schema name.
            entitySchemaName: "Activity",
            // Section view model methods.
            methods: {
                // Defines if the menu option is enabled.
                isCustomActionEnabled: function() {
                    // Attempt to receive the selected record indentifier array. 
                    var selectedRows = this.get("SelectedRows");
                    // If the array contains some elements (at least one of the records is selected from the list),
                    // it returns true, otherwise — false.
                    return selectedRows ? (selectedRows.length > 0) : false;
                },
                // Action handler method. Sets the [Completed] status for the selected records. 
                setAllDone: function() {
                    // Receiving the selected record indentifier array.
                    var selectedRows = this.get("SelectedRows");
                    // The procession starts if at least one record is selected. 
                    if (selectedRows.length > 0) {
                        // Creation of the batch query class instance.
                        var batchQuery = this.Ext.create("Terrasoft.BatchQuery");
                        // Update of each selected record.
                        selectedRows.forEach(function(selectedRowId) {
                            // Creation of the UpdateQuery class instance with the Activity root schema.
                            var update = this.Ext.create("Terrasoft.UpdateQuery", {
                                rootSchemaName: "Activity"
                            });
                            // Applying filter to determine the record for update. 
                            update.enablePrimaryColumnFilter(selectedRowId);
                            // The "Success" value is set to the Status column via
                            // the ConfigurationConstants.Activity.Status.Done.
                            update.setParameterValue("Status", ConfigurationConstants.Activity.Status.Done,
                                                    this.Terrasoft.DataValueType.GUID);
                            // Adding a record update query to the batch query. 
                            batchQuery.add(update);
                        }, this);
                        // Batch query to the server.
                        batchQuery.execute(function() {
                            // Record list update.
                            this.reloadGridData();
                        }, this);
                    }
                },
                // Overriding the base virtual method, returning the section action collection. 
                getSectionActions: function() {
                    // Calling of the parent method implementation, 
                    // returning the initialized section action collection.
                    var actionMenuItems = this.callParent(arguments);
                    // Adding separator line.
                    actionMenuItems.addItem(this.getButtonMenuItem({
                        Type: "Terrasoft.MenuSeparator",
                        Caption: ""
                    }));
                    // Adding a menu option to the section action list. 
                    actionMenuItems.addItem(this.getButtonMenuItem({
                        // Binding the menu option title to the localized schema string.
                        "Caption": { bindTo: "Resources.Strings.AllDoneCaption" },
                        // Binding of the action handler method.
                        "Click": { bindTo: "setAllDone" },
                        // Binding the menu option enable property to the value that returns the isCustomActionEnabled method.
                        "Enabled": { bindTo: "isCustomActionEnabled" },
                        // Multiselection mode enabling.
                        "IsEnabledForSelectedAll": true
                    }));
                    // Returning of the added section action collection. 
                    return actionMenuItems;
                }
            }
        };
    });

After saving the schema and updating the app page with clearing the cache you will be able to apply the [Completed] status to several selected activities in the [Activities] section by using the new [Mark as Completed] action.

Fig. 2. Case result demonstration

Example 2

Case description

Implement action for the [Activities] section list that will call the record owner selection window and set the selected value for several selected list activities.

Source code

You can download the package with case implementation using the following link.

Case implementation algorithm

1. Create a replacing page of the [Activities] section in the custom package

The procedure for creating a replacing page is described in the“Creating a custom client module schema” article.

2. Add a string with the [Actions] menu title to the localized string collection of the section replacing schema

Populate the following values for the created string (Fig.3):

  • [Name] – "SetOwnerCaption";
  • [Value] – "Assign Owner”.

Fig. 3. Properties of the custom localizable string

3. Add the implementation of the following methods to the method collection of the section view model

  • isCustomActionEnabled() – the method that determines if the added menu option is enabled.
  • setOwner() – the action handler method that calls opening of the [Contacts] lookup.
  • lookupCallback() – the callback-method that sets the lookup selected contact as the owner for the selected list records.
  • getSectionActions() – an overridden parent schema method that gets the section action collection.

The replacing schema source code is as follows:

define("ActivitySectionV2", ["ConfigurationConstants"],
    function(ConfigurationConstants) {
        return {
            // Section schema name.
            entitySchemaName: "Activity",
            // Section view model methods.
            methods: {
                // Defines if the menu option is enabled. 
                isCustomActionEnabled: function() {
                    // Attempt to receive the selected record indentifier array
                    var selectedRows = this.get("SelectedRows");
                    // If the array contains some elements (at least one of the records is selected from the list),
                    // it returns true, otherwise — false.
                    return selectedRows ? (selectedRows.length > 0) : false;
                },
                // Action handler method. Opens the [Contacts] lookup.
                setOwner: function() {
                    // Defining the lookup configuration.
                    var config = {
                        // The [Contact] Schema.
                        entitySchemaName: "Contact",
                        // Multiple selection is disabled.
                        multiSelect: false,
                        // The displayed column — [Name].
                        columns: ["Name"]
                    };
                    // Opening of the lookup with certain configuration and call-back function that is triggered
                    // after you click [Select].
                    this.openLookup(config, this.lookupCallback, this);
                },
                //  Sets the lookup selected contact as the owner
                // for the selected list records.
                lookupCallback: function(args) {
                    // The selected lookup record identifier.
                    var activeRowId;
                    // Receiving of the lookup selected records. 
                    var lookupSelectedRows = args.selectedRows.getItems();
                    if (lookupSelectedRows && lookupSelectedRows.length > 0) {
                        // Receiving of the first lookup selected record Id.
                        activeRowId = lookupSelectedRows[0].Id;
                    }
                    // Receiving of the selected record identifier array. 
                    var selectedRows = this.get("SelectedRows");
                    // The procession starts if at least one record is selected from the list and the owner is selected 
                    // in the lookup.
                    if ((selectedRows.length > 0) && activeRowId) {
                        // Creation of the batch query class instance.
                        var batchQuery = this.Ext.create("Terrasoft.BatchQuery");
                        // Update of each selected record.
                        selectedRows.forEach(function(selectedRowId) {
                            // Creation of the UpdateQuery class instance with the Activity root schema.
                            var update = this.Ext.create("Terrasoft.UpdateQuery", {
                                rootSchemaName: "Activity"
                            });
                            // Applying filter to determine the record for update. 
                            update.enablePrimaryColumnFilter(selectedRowId);
                            // The [Owner] column is populated with the value that equals to
                            // the lookup selected contact id.
                            update.setParameterValue("Owner", activeRowId, this.Terrasoft.DataValueType.GUID);
                            // Adding a record update query to the batch query. 
                            batchQuery.add(update);
                        }, this);
                        // Batch query to the server.
                        batchQuery.execute(function() {
                            // Record list update.
                            this.reloadGridData();
                        }, this);
                    }
                },
                // Overriding the base virtual method, returning the section action collection. 
                getSectionActions: function() {
                    // Calling of the parent method implementation, 
                    // returning the initialized section action collection.
                    var actionMenuItems = this.callParent(arguments);
                    // Adding separator line.
                    actionMenuItems.addItem(this.getButtonMenuItem({
                        Type: "Terrasoft.MenuSeparator",
                        Caption: ""
                    }));
                    // Adding a menu option to the section action list.
                    actionMenuItems.addItem(this.getButtonMenuItem({
                        // Binding the menu option title to the localized schema string.
                        "Caption": { bindTo: "Resources.Strings.SetOwnerCaption" },
                        // Binding of the action handler method.
                        "Click": { bindTo: "setOwner" },
                        // Binding the menu option enable property to the value that returns the isCustomActionEnabled method.
                        "Enabled": { bindTo: "isCustomActionEnabled" },
                        // Multiselection mode enabling.
                        "IsEnabledForSelectedAll": true
                    }));
                    // Returning of the added section action collection.
                    return actionMenuItems;
                }
            }
        };
    });

After saving the schema and updating the app page with clearing the cache you will be able to change the owner of several selected activities in the [Activities] section by using the new [Assign Owner] action.

Fig. 4. Case result demonstration

See also

 

© bpm'online 2002-2019.

Did you find this information useful?

How can we improve it?