Dynamically Adding a Tile to the SAP Fiori Launchpad

How to Dynamically Add a Tile to the SAP Fiori Launchpad

Some time ago, I explored the option of adding a tile to the SAP Fiori Launchpad.

See the post: How to Add a Tile to the SAP Fiori Launchpad?

In this note, I want to look at an implementation approach that can be used when a customer requires dynamically adding a tile to a user's launchpad — that is, based on certain conditions being met.

What Will I Need for This?

A launchpad plugin

See: Создание плагина для SAP Fiori Launchpad

An OData service to determine whether a tile should be added to the launchpad

See: Создание Web приложения с помощью фреймворка SAPUI5 (6)

Class sap.ushell.services.Bookmark

See: class sap.ushell.services.Bookmark

Objective

Add a tile to the SAP Fiori Launchpad for a user, provided that the user has been assigned a specific role in the backend system. The new tile can be added without linking it to a specific tile catalog already available to the user.

OData Service to Check for User Role

The OData service I plan to use to determine whether the user has the required role contains an EntitySet with the following properties.

See:  Create Entity Sets

The population of the required EntitySet is implemented in the *DPC_EXT class of the OData service.

See: Extending an OData Service Using Service Builder

Example:

METHOD roleexist_get_entityset.
 
 
    DATA: ls_entity_set LIKE LINE OF et_entityset.
 
 
    LOOP AT it_filter_select_options ASSIGNING FIELD-SYMBOL(<fs_filt>).
      CASE <fs_filt>-property.
        WHEN 'roleName'.
          DATA(lv_carrid) = <fs_filt>-select_options.
          LOOP AT <fs_filt>-select_options ASSIGNING FIELD-SYMBOL(<fs_options>).
            DATA(lv_role_from_front) = <fs_options>-low.
          ENDLOOP.
 
      ENDCASE.
    ENDLOOP.
 
    IF lv_role_from_front IS NOT INITIAL.
 
      SELECT SINGLE agr_name INTO @DATA(lv_agr_name) FROM agr_users WHERE uname = @sy-uname AND agr_name EQ @lv_role_from_front AND to_dat EQ '99991231'.
      IF lv_agr_name IS NOT INITIAL.
        APPEND VALUE #(
        roleid = lv_role_from_front
        isexists = abap_true
        rolename = get_role_name( lv_agr_name )
        ) TO et_entityset.
      ELSE.
        APPEND VALUE #(
          roleid = '-'
          isexists = '-'
          rolename = '-'
          ) TO et_entityset.
      ENDIF.
    ELSE.
      APPEND VALUE #(
     roleid = '-'
     isexists = '-'
     rolename = '-'
     ) TO et_entityset.
    ENDIF.
 
  ENDMETHOD.

Populating the SAP Fiori Launchpad Plugin

Example implementation of the onInit() function:

See:  SAP Fiori Launchpad Extensibility
init: function() {
 
            var oBookmarkService = sap.ushell.Container.getService("Bookmark");
            var sUrl = "/sap/opu/odata/SAP/ZAPP14_SRV_01";
 
            var oDataModel = new sap.ui.model.odata.v2.ODataModel(sUrl, {
                json: true
            });
            var oFilters = [new sap.ui.model.Filter("roleName", "EQ", "ZDEVELOPER")];
 
            oDataModel.read(\'/roleExist\', {
                filters: oFilters,
                success: function(oData, response) {
                    var oFlpModel = new sap.ui.model.json.JSONModel({});
                    oFlpModel.setData(oData.results);
                    sap.ui.getCore().setModel(oFlpModel, "oFlpMdl");
                },
                error: function(oError) {}
            });
 
            oDataModel.attachBatchRequestCompleted(function(oData) {
                var oRole = sap.ui.getCore().getModel("oFlpMdl").getData(oData);
                if (oRole[0].isExists === "X") {
 
                    oBookmarkService.countBookmarks("#ZBOOKMARK-display").done(function(iCount) {
                        var oRoleModel2 = new sap.ui.model.json.JSONModel({});
                        oRoleModel2.setData(iCount);
 
                        switch (iCount) {
                            case (0):
                                oBookmarkService.addBookmark({
                                    title: "Application title",
                                    url: "#ZBOOKMARK-display",
                                    icon: "sap-icon://developer-settings",
                                    info: "Dynamic tile loaded",
                                    subtitle: oRole[0].roleName
                                });
                                break;
                            case (1):
                                return;
                                break;
                            case (2):
                                oBookmarkService.deleteBookmarks("#ZBOOKMARK-display");
                                break;
                            default:
                                return;
                                break;
                        }
                    }).fail(function(sMessage) {
                    });
                } else {
                    oBookmarkService.deleteBookmarks("#ZBOOKMARK-display");
                }
 
            });
        }

Target Mapping Configuration for the Tile

To ensure that the application launches when the user clicks on the added tile, you need to configure Target Mapping in one of the catalogs available to the user.

See: Configuring Navigation

See: Configuring Target Mappings

Testing

0:00
/1:34

Thank you for your time. Winter will be long, but everything will work out as usual.

Hugs, ignatov