How to add a section action: handling the selection of several records
Glossary Item Box
Introduction
The section single record mode is used by default. To select multiple active list records use the [Select multiple records] option in the [Actions] button menu. The list visual view will change – you will see record selection elements appear. To cancel the multiple record mode, click [Cancel multiple selection] in the [Actions] button menu.
Case description
Implement an action, which displays account names of several selected list orders in the message window for the [Orders] section list.
ATTENTION The [Orders] section is available in bpm’online sales products. |
NOTE The primary column values of the selected records are stored in the SelectedRows property of the section view model. These values can further be used for getting the values, downloaded into the selected object field list, for instance, from a regular list data collection, which is stored in the GridData list view model property. |
Source code
Use this link to download the case implementation package.
Case implementation algorithm
1. Create a replacing page of the [Orders] section in the custom package
Create a replacing client module and specify the OrderSectionV2 schema as parent object (Fig. 1). The procedure for creating a replacing page is described in the “Creating a custom client module schema” article.
Fig. 1. Properties of the [Orders] section replacing page
2. Add a string with the [Actions] menu title to the localized string collection of the section replacing schema
Create a new localized string (Fig.2).
Fig. 2 – Adding the localized string to the schema
Populate the following values for the created string (Fig.3):
- [Name] – “AccountSectionAction”
- [Value] – “Accounts for the selected orders”
Fig. 3. Custom localized string properties
3. Add method implementation to the section view model method collection
- isCustomActionEnabled() – determines if the added menu option is enabled.
- showOrderInfo() – the action handler method that displays the selected order account list in the message window.
- getSectionActions() – an overridden parent schema method that gets the section action collection.
The replacing schema source code is as follows:
define("OrderSectionV2", ["OrderConfigurationConstants"], function(OrderConfigurationConstants) { return { // Section schema name. entitySchemaName: "Order", // Section view model methods. methods: { // Determines if the menu option is enabled. isCustomActionEnabled: function() { // Attempt of getting the selected record identifier array. var selectedRows = this.get("SelectedRows"); // If the array contains any elements (at least one list record is selected), // it gets true, otherwise - it gets false. return selectedRows ? (selectedRows.length > 0) : false; }, // Action handler method. Displays the account list in the message window. showOrdersInfo: function() { // Getting the selected record identifier array. var selectedRows = this.get("SelectedRows"); // Getting the list record data collection. var gridData = this.get("GridData"); // Variable for stoarge of the selected order object model. var selectedOrder = null; // Variable for stoarge of the selected order account name. var selectedOrderAccount = ""; // Variable for the message window text. var infoText = ""; // Handling of the selected section record identifier array. selectedRows.forEach(function(selectedRowId) { // Getting the selected order object model. selectedOrder = gridData.get(selectedRowId); // Getting the selected order account name. The column must be added to the list. selectedOrderAccount = selectedOrder.get("Account").displayValue; // Adding the account name to the message window text. infoText += "\n" + selectedOrderAccount; }); // Message window display. this.showInformationDialog(infoText); }, // Overriding the base virtual method that gets the section action collection. getSectionActions: function() { // Calling of the method parent implementation for getting the // initiated action collection of the section. var actionMenuItems = this.callParent(arguments); // Adding a separator line. actionMenuItems.addItem(this.getButtonMenuItem({ Type: "Terrasoft.MenuSeparator", Caption: "" })); // Adding a menu option to the section action list. actionMenuItems.addItem(this.getButtonMenuItem({ // Linking the menu option title to the schema localized string. "Caption": {bindTo: "Resources.Strings.AccountsSectionAction"}, // Action handler method linking. "Click": {bindTo: "showOrdersInfo"}, // Linking of the menu option enabling property to the value that gets // the isCustomActionEnabled method. "Enabled": {bindTo: "isCustomActionEnabled"}, // Multiselection mode enabling. "IsEnabledForSelectedAll": true })); // Getting the appended section action collection. return actionMenuItems; } } }; });
After you save the schema and update the application page with clearing the browser cache, a new action appears in the [Orders] section. It will be active when you select orders in the multiple record selection mode (Fig.4).
Fig. 4. Case result
See also
- Adding an action to the list
- How to add a section action: handling the selection of a single record
- Handling the selection of several records. Examples