Article

Change of the field value of multiple records using custom action

Case description:

We need to edit field of some record using custom action in the section. We will add 2 extra  fields (Warranty Period, Delivery Period) in the section. When we search product, We would like to realize the following function:

Section-> Actions-> Select multiple records > Change Warranty Period or Change Delivery Period. You can see it in the Figure 0.

Figure 0. Custom action using for data update.

In this case, there should be a small popup and I we change the value there.

Algorithm of realization.

  1. Create replacing page of section .
  2. Add localizable string like "Resources.Strings.MultiplyChangeAction" and bind this string to caption.



    Figure 1. Localizable string properties.



     
  3. Add function “isCustomActionEnabled” that determines conditions of the clickability of the action. This function determines whether the action is active. In our example, the action is active if at least an entry is selected.

     

    isCustomActionEnabled: function() {
                        var selectedRows = this.get("SelectedRows");
                        return selectedRows ? (selectedRows.length > 0) : false;
                    },  

     

  4. Add function "getSectionActions" is an owerriden virtual method in which to bind the handler method to an action. 

    getSectionActions: function() {
                        var actionMenuItems = this.callParent(arguments);
                        actionMenuItems.addItem(this.getButtonMenuItem({
                            "Caption": {bindTo: "Resources.Strings.MultiplyChangeAction"},
                            "Click": {bindTo: "showLoanInfo"},
                            "Enabled": {bindTo: "isCustomActionEnabled"}
                        }));
                        return actionMenuItems;
                    }

     

  5.  Add function "showLoanInfo" - action handler method which will show the user a window for data entry using "Terrasoft.utils.inputBox". After user clicks "OK", we need to update the record. 

    showLoanInfo: function() {
                    Terrasoft.utils.inputBox("Set fields for update", function(result, arg) {
                            if (result === Terrasoft.MessageBoxButtons.YES.returnCode) {
                                var warrantyPeriod = arg.warranty.value;
                                var deliveryPeriod= arg.delivery.value;
                                var autoIds = this.getSelectedItems();
                                this.updateProduct(function(context, result) {
                                }, autoIds, deliveryPeriod, warrantyPeriod);
     
                            }
                        }, [{
                            className: "Terrasoft.Button",
                            caption: "OK",
                            returnCode: "yes"
                        }, "cancel"], this,
                        {
                            warranty: {
                                dataValueType: Terrasoft.DataValueType.INTEGER,
                                caption: "Warranty",
                                customConfig: {
                                    className: "Terrasoft.MemoEdit",
                                    height: "17px"
                                }
                            },
                            delivery: {
                                dataValueType: Terrasoft.DataValueType.INTEGER,
                                caption: "Term",
                                customConfig: {
                                    className: "Terrasoft.MemoEdit",
                                    height: "17px"
                                }
                            }
                        },
                        {
                            defaultButton: 0,
                            style:  {
                                borderStyle: "ts-messagebox-border-style-blue ts-messagebox-border-no-header",
                                buttonStyle: "blue"
                            }
                        }
                    );
                },

    You can see generated Pop-Up in the next Figure.

    Figure 2. Pop-Up using for multiply update.

  6.  Add update function using "Terrasoft.UpdateQuery". We choose a filter of type "OR" to choise selected records. 

updateProduct: function(callback, autoIds, valueWarranty, valueDelivery) {
                        var update = Ext.create("Terrasoft.UpdateQuery", {
                            rootSchemaName: "Product"
                        });
                        var filters = Terrasoft.createFilterGroup();
                        filters.logicalOperation = Terrasoft.LogicalOperatorType.OR;
                        autoIds.forEach(function(item) {
                            var productIdFilter = update.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL,
                            "Id", item);
                            filters.add("ProductIdFilter" + item, productIdFilter);
                        }, this);
                        update.filters.add(filters);
                        if (valueWarranty) {
                            update.setParameterValue("UsrWaranty", valueWarranty, Terrasoft.DataValueType.TEXT);
                        }
                        if (valueDelivery) {
                            update.setParameterValue("UsrDelivery", valueDelivery, Terrasoft.DataValueType.TEXT);
                        }
                        update.execute(function(result) {
                            callback.call(this, result);
                        }, this);
                    },

 

Like 2

Like

Share

5 comments

Hello, I think isCustomActionEnabled function not working when I click Select All button.

 

Do you have any suggestion? I made some tracing and this function is calling and returning true. but custom action button is not enabled.

 

But if I manually select one/some/all rows it is enabled. Also, when I manually select all rows and then click Select All button, it is somehow setting disabled state.



For test, I returned true always from bind function.

Also, I removed Enable binding and got same result

 

I found one property which is necessary to enable this menu item on select all.

"IsEnabledForSelectedAll": true

Hi Luka,

 

The custom action is not active when using Select All option on purpose. The majority of default actions are not active as well. It is designed to prevent changing all data in the section, for example from deleting data or merging it. That's why majority of actions are greyed out in the drop down list.

 

Regards,

Dean

Hello,

Is callback function not required here?

This not working without it. Please provide the definition for it.

Show all comments