Feature Toggles are gaining popularity amongst S/4HANA Cloud developers. Toggles are live since 1705 for Hidden Code delivery use case. Currently ABAP code can be fully toggled. One of the most requested technology enablement is UI (especially Smart Templates and Fiori Launchpad Content). As a first step towards UI toggling, we (the Feature Management Team of Cloud Foundation) developed a UI Library that simplifies UI elements toggling to some extent.
Currently, to implement Feature Toggle in Fiori apps, we need to either add an entity set in our oData service or do an association with our Feature Toggle CDS views. This involves modification of the backend service.
A better approach to fetch toggle status is to use the Feature Toggle UI Library. Using the UI Library, the developer can obtain the toggle status of a feature by simply calling the library function without any other implementation in the application (i.e. without modifying the backend service). With this, you can toggle UI elements in a freestyle app or write breakout exit for a Smart Template app.
The library is implemented in the UI application as follows:
- Add the following code in the pom.xml file of your project.
<dependencies> <dependency> <groupId>com.sap.fiori</groupId> <artifactId>s4h.cfnd.featuretoggle.lib</artifactId> <version>1.0.5-SNAPSHOT</version> </dependency> </dependencies>
- Add the library (sap.s4h.cfnd. featuretoggle) as a dependency in your project, in either the manifest.json file or the Component.js file if the manifest.json does not exist.
- Call the getFeatureStatus() function of the library and pass the Feature ID for the toggle you wish to use.
// Calling the UI Library to get Feature Toggle Status var sStatus = sap.s4h.cfnd.featuretoggle.lib.features().getFeatureStatus("FeatureID"); // Using the Toggle Status value to toggle UI content this.byId("UIContentID").setVisible(sStatus);
The toggle status returned by this function can be used to toggle any UI element in the Fiori application.
If the toggle does not exist, the default value returned by the function is ‘true’.
Advantages of using the UI library:
- No additional oData round trip inside the application: Once the library is loaded, it makes an oData call to fetch the toggle status of all the features and stores them in the cache. So even if the application calls the getFeatureStatus() function multiple times, no additional oData calls are made. This improves the performance of the application.
- No additional oData round trip across applications: If one app loads the library and the oData call is made to fetch the toggle status of all features, the data is available in the cache and can be used by all applications in the launchpad. So even if there are multiple applications using the UI Library to fetch the statuses of their respective toggles, there will be only one oData call in one session which will provide the toggle status to all the applications.
- No changes needed in the existing oData service to fetch toggle status: The developer only needs to call the UI library.
- Loading time of the app with and without library: The application having the library as a dependency takes an average time of 0.08 sec more to load than the app which does not use the library.
For more information, you can visit the following links: