Define custom actions by using the extensions in the app descriptor file. You can also define these custom actions so that they appear on charts, tables, or header toolbars based on the filter property value (chart/table/global).
This topic is only applicable to SAP Fiori elements for OData V2.
You can also define custom actions in SAP Fiori elements for OData V4. For more information, see Adding Custom Actions Using Extension Points.
To correctly integrate your app extension coding with SAP Fiori elements, use only the
extensionAPI
of SAP Fiori elements. For more information, see Using the extensionAPI.
Use the getSelectedContexts()
API in the extensionAPI
class to get the selection context. For buttons in the chart toolbar, pass the event ID as a parameter.
The analytical list page supports keyboard shortcut keys for custom actions defined in the manifest for global actions and chart/table toolbar actions.
In your app's manifest.json
file, under sap.ui5
→ extends
→ extensions
, you can specify extensions for the AnalyticalListPage
controllers.
You can specify the following information and extend the manifest files as described here:
Property |
Description |
---|---|
|
Entity set that is displayed on the analytical list page. (For example
|
|
The names of actions. |
|
The ID that is used for the action button. |
|
The |
|
The handler function that is called when the user selects the action button. |
|
Indicates whether this is a global action. The default value is
|
|
Indicates whether the action requires a selection of items. The default value is |
|
Indicates whether the action should be displayed in the footer of the page. The default value is |
|
Represents the command mapped to a keyboard shortcut defined under
|
"sap.ui5": {
"_version": "1.1.0",
"extends": {
"extensions": {
"sap.ui.commands": {
"sap.suite.generic.template.AnalyticalListPage#sap.suite.generic.template.AnalyticalListPage::ZCostCenterCostQuery0020": {
"GlobalActionCommand": {
"shortcut": "Ctrl+B"
}
}
},
"sap.ui.controllerExtensions": {
"sap.suite.ui.generic.template.AnalyticalListPage.view.AnalyticalListPage": {
"controllerName": "my_app.ext.controller.AnalyticalListPageExt",
"sap.ui.generic.app": {
"ZCostCenterCostQuery0020": {
"EntitySet": "ZCostCenterCostQuery0020",
"Actions": {
"Action A": {
"id": "ActionA",
"text": "{{Action A}}",
"press": "onClickActionA",
"global": true,
"command": "GlobalActionCommand ",
},
"Action B": {
"id": "ActionB_requiresSelection",
"text": "{{Action B}}",
"press": "onClickActionB",
"filter": "table",
"requiresSelection":true
}
"Action C: {
"id": "ActionC_requiresSelection",
"text": "{{Action C}}",
"press": "onClickActionC",
"filter": "chart",
"requiresSelection":true
}
"Action D": {
"id": "ActionD",
"text": "{{Action D}}",
"press": "onClickActionD",
"filter": "table"
}
"Action E: {
"id": "ActionE",
"text": "{{Action E}}",
"press": "onClickActionE",
"filter": "chart"
}
} //End of Custom Actions
} // End of entity type ZCostCenterCostQuery0020
}
} // End of ALP controllerExtensions
} // End of controllerExternsions
}
},
....,
....
}
Custom actions defined in the application's custom controller:
sap.ui.define([], function () { return { onBeforeRebindTableExtension: function (oEvent) { console.log('onBeforeRebindTableExtension called!'); }, onBeforeRebindChartExtension: function (oEvent) { console.log('onBeforeRebindChartExtension called!'); }, onClickActionA() { console.log('Global Action Shortcut Key triggers'); alert('Button A shows up only in table toolbar and is clicked toolbar!'); }, onClickActionB() { // The "getSelectedContexts" should be invoked from synchronous code block. // // The results of "getSelectedContexts" is cached on "aContexts" and // passed as a parameter to the callback function "onActionConfirm". var aContexts = this.extensionAPI.getSelectedContexts(); sap.m.MessageBox.confirm("Would you like to perform the action", { title: "Confirm", actions: [sap.m.MessageBox.Action.OK, sap.m.MessageBox.Action.CANCEL], emphasizedAction: sap.m.MessageBox.Action.OK, onClose: this.onActionConfirm.bind(this, aContexts) }); }, onActionConfirm(aContexts, sAction) { if (sAction === sap.m.MessageBox.Action.OK) { this.extensionAPI.invokeActions("/ActionB", aContexts).then(function () { /// }); } }, onClickActionC() { var contexts = this.extensionAPI.getSelectedContexts(oEvent.ID); alert('Button C which shows up in chart toolbar only is clicked!'); }, onClickActionD() { alert('Button D which shows up in table toolbar only is clicked!'); }, onClickActionE() { alert('Button E which shows up in chart toolbar only is clicked!'); } } })
This extension API lets you invoke any back-end action from the controller extensions (standard SAPUI5 API methods). For example:
onClickActionSTTA_C_SO_SalesOrder_ND1: function(oEvent) {
var oApi = this.extensionAPI;
var mParameters = {
"SalesOrderID": "500000052"
};
oApi.invokeActions("STTA_SALES_ORDER_ND_SRV_01/AFF8CCF97ACESave_stta_i_so_salesorder_nd", [], mParameters);
}
Related Information