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

Handling the selection of several records. Examples

Glossary Item Box

We recommend to preliminary study the case to add an action to the section in the mode of multiple records selection in the How to add a section action: handling the selection of several records.

Below are the examples of handling multiple records using a custom action.

Example 1

Case description

Implement the action for the [Activity] section, which sets the [Completed] status for several activities selected in the list.

Case implementation algorithm

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

The process of creating the replacing page is described in the Creating a custom client module schema.

2. Add a string with the [Actions] menu item to the collection of localizable strings in the replacingsection schema

Fill in properties for the created string as shown in Figure 1.

Fig. 1. — Properties of a custom localized string

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

  • isCustomActionEnabled — the method that will determine the availability of the added menu item;
  • setAllDone — the action handler method that will set the [Completed] status for several activities selected in the list;
  • getSectionActions — the redefined virtual method wherein the handler method should be bound to an action.

Below is the code of the section replacing schema.

define("ActivitySectionV2", ["ConfigurationConstants"],
    function (ConfigurationConstants) {
        return {
            // Name of the section schema.
            entitySchemaName: "Activity",
            // Methods collection of the section view model.
            methods: {
                // Method ddefines whether the menu item will be available. 
                isCustomActionEnabled: function () {
                    // At attempt to receive Id massive of the selected records.
                    var selectedRows = this.get("SelectedRows");
                    // If the massive contains elements (i.e. even if one record is selected in the list), 
                    // true is returned; otherwise false is present.
                    return selectedRows ? (selectedRows.length > 0) : false;
                },
                // Action handler method setting the “Completed” status for selected records.
                setAllDone: function () {
                    // Receiving the massive of values in primary columns of selected records.
                    var selectedRows = this.get("SelectedRows");
                    // Processing is started only if even one record is selected.
                    if (selectedRows.length > 0) {
                        // Creating an instance of the package request class.
                        var batchQuery = this.Ext.create("Terrasoft.BatchQuery");
                        // Updating each of the selected records.
                        selectedRows.forEach(function (selectedRowId) {
                            // Creating an instance of the UpdateQuery class with the Activity core schema.
                            var update = this.Ext.create("Terrasoft.UpdateQuery", {
                                rootSchemaName: "Activity"
                            });
                            // Using the filter to determine a record to be updated. 
                            update.enablePrimaryColumnFilter(selectedRowId);
                            // Set the "Completed" value for the Status column using the 
                            // ConfigurationConstants.Activity.Status.Done configuration constant. 
                            update.setParameterValue("Status",
                                ConfigurationConstants.Activity.Status.Done, this.Terrasoft.DataValueType.GUID);
                            // Adding a request for a record update to a package request.
                            batchQuery.add(update);
                        }, this);
                        // Fulfilling the package request to the server. 
                        batchQuery.execute(function () {
                            // Updating the list.
                            this.reloadGridData();
                        }, this);
                    }
                },

                getSectionActions: function () {
                    // The parent implementation of the method is called to receive
                    // the initiated actions collections for the base section. 
                    var actionMenuItems = this.callParent(arguments);
                    // Adding a separators line to visually separate the user action from the list 
                    // of actions in the base section. 
                    actionMenuItems.addItem(this.getButtonMenuItem({
                        Type: "Terrasoft.MenuSeparator", 
                        Caption: ""
                    }));
                    // Adding a menu item to the section actions list.
                    actionMenuItems.addItem(this.getButtonMenuItem({
                        // Binding the menu item title to the localizable schema string.
                        "Caption": { bindTo: "Resources.Strings.AllDoneCaption" },
                        // Binding the action handler method.
                        "Click": { bindTo: "setAllDone" },
                        // Binding the availability property of the menu item to the value which returns the isCustomActionEnabled method.
                        "Enabled": { bindTo: "isCustomActionEnabled" }
                    }));
                    return actionMenuItems;
                }
            }
        };
    });

4. Save the created replacing schema

When the schema is saved and the system web-page is updated, the [Completed] status may be used for several selected activities at once in the [Activities] section using the new [Mark as “Completed”] action (Fig. 2).

Fig. 2. – Result demonstration

Example 2

Case description

Implement the action for the [Activities] section, which calls the owner selection window and set the selected value for several activities selected in the list.

Case implementation algorithm

1. Create the [Activities] replacingsection page in a custom package

The process of creating a replacing page is described in the article Creating a custom client module schema.

2. Add a string with the menu item titled [Actions] to the collection of localizable strings in the replacingsection schema

Fill in properties for the created string as shown in Figure 3.

Fig. 3. — Properties of a custom localizable string

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

  • isCustomActionEnabled — the method determining the accessibility of an added menu item;
  • setOwner — the action handler method calling the opening of the [Contacts] lookup;
  • lookupCallback — the callback method setting the contact selected in the lookup as the owner for records selected in the list;
  • getSectionActions — the redefined virtual method wherein the handler method must be bound to an action.

Below is the code of the section replacing schema.

define("ActivitySectionV2", ["ConfigurationConstants"],
    function (ConfigurationConstants) {
        return {
            // Name of the section schema.
            entitySchemaName: "Activity",
            // Methods collection of the section view model.
            methods: {
                // The method determines whether the menu item will be available.
                isCustomActionEnabled: function () {
                    // At attempt to receive an array of selected record identifiers is made. 
                    var selectedRows = this.get("SelectedRows");
                    // If the array contains elements (i.e. even if one record is selected in the list),
                    // true is returned; otherwise false is present.
                    return selectedRows ? (selectedRows.length > 0) : false;
                },
                // Action handler method calling the [Contacts] lookup opening.
                setOwner: function () {
                    // Determining the configuration of the opened lookup: [Contact] schema; multiple
                    // selection is disabled; the displayed column is  [Name]. 
                    var config = {
                        entitySchemaName: "Contact",
                        multiSelect: false,
                        columns: ["Name"]
                    };
                    // Opening the lookup with a certain configuration and callback function which will actuate
                    // when the [Select] button is clicked. 
                    this.openLookup(config, this.lookupCallback, this);
                },
                // Method setting the contact selected in the lookup as the owner
                // for records selected in the list.
                lookupCallback: function (args) {
                    var activeRowId;
                    var lookupSelectedRows = args.selectedRows.getItems();
                    if (lookupSelectedRows && lookupSelectedRows.length > 0) {
                        // Receiving the Id of the record selected in the lookup.
                        activeRowId = lookupSelectedRows[0].Id;
                    }
                    // Receiving the array of values in primary columns of selected records.
                    var selectedRows = this.get("SelectedRows");
                    // Processing starts only if even one record is selected in the list and the owner is selected 
                    // in the lookup.
                    if ((selectedRows.length > 0) && activeRowId) {
                        // Creating an instance of the package request class.
                        var batchQuery = this.Ext.create("Terrasoft.BatchQuery");
                        // Updating each of the selected records.
                        selectedRows.forEach(function(selectedRowId) {
                            // Creating an instance of the UpdateQuery class with the Activity core schema.
                            var update = this.Ext.create("Terrasoft.UpdateQuery", {
                                rootSchemaName: "Activity"
                            });
                            // Using the filter to determine a record to be updated.
                            update.enablePrimaryColumnFilter(selectedRowId);
                            // Set the value for the [Owner] column, which is equal to the contact selected in the lookup.
                            update.setParameterValue("Owner", activeRowId, this.Terrasoft.DataValueType.GUID);
                            // Adding a request for a record update to a package request.
                            batchQuery.add(update);
                        }, this);
                        // Fulfilling the package request to the server. 
                        batchQuery.execute(function() {
                            // Updating the list. 
                            this.reloadGridData();
                        }, this);
                    }
                },
                // Overriding  the base virtual method returning the section actions collection.
                getSectionActions: function () {
                    // The parent implementation of the method is called to receive
                    // the initiated actions collections for the base section. 
                    var actionMenuItems = this.callParent(arguments);
                    // Adding a separator line for visual separation of the custom action 
                    // from the list of actions for the base section. 
                    actionMenuItems.addItem(this.getButtonMenuItem({
                        Type: "Terrasoft.MenuSeparator", 
                        Caption: ""
                    }));
                    // Adding a menu item to the section actions list.
                    actionMenuItems.addItem(this.getButtonMenuItem({
                        // Binding the menu item title to the localizable schema string.
                        "Caption": { bindTo: "Resources.Strings.SetOwnerCaption" },
                        // Binding the action handler method.
                        "Click": { bindTo: "setOwner" },
                        // Binding the availability property of the menu item to the value which returns the isCustomActionEnabled method.
                        "Enabled": { bindTo: "isCustomActionEnabled" }
                    }));
                    return actionMenuItems;
                }
            }
        };
    });

4. Save the created replacing schema

When the schema is saved and the system web-page is updated, the “Owner” field of several selected activities may be modified in the [Activities] section using the new [Assign Owner] action (Fig. 4).

Fig. 4. – Result demonstration

 

© bpm'online 2002-2017.

Did you find this information useful?

How can we improve it?