cancel
Showing results for 
Search instead for 
Did you mean: 

how to add a custom action button to a Fiori Element app which displays row data for 1909?

Peter_M
Explorer
0 Kudos

There are many examples which show how to extend a Fiori Element "list" app with a custom "requires selection" button, where the behaviour of this new button is as follows:

  • It only becomes visible when a row is selected
  • When the button is pressed, it shows static text like "hello world" in a message toast.

That is fine, but what if you want adapt the controller code to access a field in the row data of the list. Does anyone know how to achieve this within an extension to a FE app for 1909?

There seems to be nothing on-line that details how to do this in VsCode !! (for a fiori element app that has been developed in VsCode, but has not yet been deployed)

Here is some example coding in 2 files that show how to extend a Fiori Elements "list" app to show static text

In controler extension

sap.ui.define([
    "sap/m/MessageToast"
], function(MessageToast) {
    'use strict';

    return {
        showData: function(oEvent) {
            MessageToast.show("Hello World");
	    }
    };
});<br>

In manifest.json

         "extends": {
            "extensions": {
                "sap.ui.controllerExtensions": {
                    "sap.suite.ui.generic.template.ListReport.view.ListReport": {
                        "controllerName": "zdms.ext.controller.ListReportExt",
                        "sap.ui.generic.app": {
                            "Z_DMSMETA": {
                                "EntitySet": "Z_DMSMETA",
                                "Actions": {
                                    "showData": {
                                        "id": "showDataButton",
                                        "text": "Show Data",
                                        "press": "showData",
                                        "requiresSelection": true
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

Accepted Solutions (1)

Accepted Solutions (1)

junwu
Active Contributor
0 Kudos

Answers (2)

Answers (2)

Peter_M
Explorer
0 Kudos

OK - resolved it with extensionAPI.getSelectedContexts

Peter_M
Explorer
0 Kudos

Thanks for response but I can't get the methods to work 😞

For those looking for at least something that works, adapting the controller code to the below seems to work OK, but, it is clunky and I suspect it will break in an upgrade 😞

In this code, replace <YOURFIELDNAME> with the field you want to show

sap.ui.define([
    "sap/m/MessageToast"
], function(MessageToast) {
    'use strict';

    return {
        showData: function(oEvent) {

            var zkey = oEvent.getSource().oParent.oParent._aSelectedPaths[0].substr(1);
            var zdata = oEvent.getSource().getModel().oData;
            var zrec = "";
            Object.entries(zdata).forEach((entry) => {
                const [key, value] = entry;
                    if (key == zkey) {
                        zrec = value;
                    }; 
            });
            MessageToast.show(zrec.<YOURFIELDNAME>);      
        }
    };
});


Does anyone have a worked example using nice methods that replace this clunky code approach?