Customizing and Extending Standard Fiori Applications
Fiori standard apps are not always accepted by customers as is. Sometimes developers need to extend or modify an application according to meet the customer’s requirements. SAP Fiori has an enhancement framework that makes this task easier. In this chapter, you learn how to customize and extend the standard Fiori apps.
Installing Eclipse and UI5 Add-Ons
This chapter looks at the steps involved in extending and customizing a standard SAP Fiori app. The two primary IDEs currently used for Fiori development and customization are as follows:
To extend a standard app, you need to use the Eclipse Juno 32-bit or 64-bit version. You can go to this web page to download Eclipse:
www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/marsr
After installing Eclipse, you need to install the SAP UI5 add-ons to Eclipse. To do so, open Eclipse and then follow these steps.
Figure 4-1. UI5 add-on screen in Eclipse
To extend the Fiori applications, we need to add the Fiori Toolkit plugin into eclipse. The fiori toolkit can be downloaded from the below site http://scn.sap.com/docs/DOC-50114. (Click on the "I Agree & Download" link on the page to start the download). Once the plugin has been downloaded open the eclipse and do the following steps to install it :
Since SAP released Web IDE, the Fiori toolkit add-on version 1.1.4 for Eclipse is no longer being updated. Currently, Eclipse Luna gets the latest Fiori UI5 library add-ons. Detailed steps for downloading and configuring Eclipse and Web IDE are presented in Chapter 6.
Downloading the Standard Fiori Application Code
This scenario uses the Track Purchase Orders standard app, as shown in Figure 4-2.
Figure 4-2. Screenshot of the standard Track Purchase Orders app
First you need to find the BSP app of the Track Purchase Order app to extend it. There are two ways to find the app source code in the system.
First, you can execute the transaction SICF, navigate to /default_host/sap/bc/ui5_ui5/sap, and search for the app manually. In this scenario, the BSP app name is mm_purord_tpo (see Figure 4-3).
Figure 4-3. Manually searching for the BSP app
Or second, you can open the launchpad designer, and search for the Track Purchase Order app in the business catalog (see Figure 4-4). Then follow these steps:
Figure 4-4. Launchpad designer catalog tiles
Figure 4-5. Select the target mapping
Figure 4-6. Find the launchpad role
Figure 4-7. Search for the role
Figure 4-8. LPD_CUST launchpad settings for Track Purchase Order app
After you’ve found the app name, you need to download the app’s source code into Eclipse. SAP provides the app /UI5/UI5_REPOSITORY_LOAD to download and upload Fiori apps (both standard and custom). Follow these steps:
Figure 4-9. Downloading the Track Purchase Order app source code
Figure 4-10. Select a destination directory
Figure 4-11. Click the Click Here To Download link
Figure 4-12. Leave this field blank
Figure 4-13. Download confirmation
Now that the app has been downloaded to your local PC, you need to import the source code into Eclipse.
Importing Fiori Standard Application Code into Eclipse
Before creating an extension Fiori extension project, you have to import into Eclipse the standard code you downloaded from the server. Here are the steps:
Figure 4-14. Creating a UI5 project in Eclipse
Figure 4-15. Select Application Project
Figure 4-16. Deselect Create An Initial View
Figure 4-17. Project Explorer
Figure 4-18. Standard Track Purchase Order UI5 source code
Figure 4-19. Overwriting the UI5 Eclipse Project WebContent folder with the downloaded code
Figure 4-20. Eclipse project with the standard code
If you check one of the standard code’s views, such as S2.view.xml, you see a <core:ExtensionPoint/> tag (see Figure 4-21). This is basically a flag for the Fiori toolkit or Web IDE to find extension points where you can insert custom code into the standard code. Usually, extension points are available for Header, Maint Content, and Footer, but they may differ from view to view. Some views don’t have extension points, in which case you have the option to replace the entire view with custom code.
Figure 4-21. Extension points in the standard code
Similarly, you can see the *.controller.js and a *.-dbg.controller.js files for every controller of each view (see Figure 4-22). Files ending with *-dbg.controller.js are the expanded versions of the same code in the *.controller.js files. At runtime, the Fiori apps only load *.controller.js, unless you change the debugger settings to load *.-dbg.controller.js manually.
Figure 4-22. Standard app code
Also, you see Component-preload.js as well as a -dbg version (see Figure 4-23). Component-preload.j is basically a summary of all the code in controller.js for each view, configuration.js, and the component controller in the standard app project. This feature is extremely useful for Fiori client apps running on mobile devices, where space and loading time are critical.
Figure 4-23. Component-preload.js
Before you create an extension project, you need a custom OData service to help bring your custom data from the back end into the extended app. To check the standard OData service that is being used by the standard app, open the Configuration-dbg.js file: the OData service name is in the service list (see Figure 4-24).
Figure 4-24. OData service name
You need to create a custom OData service for the extended app. There are two ways to do it. First, you can create a completely custom OData service for the extended app, but this is not recommended because you have to adapt all the UI code to work with the new OData service entity fields. Second, you can create a new OData project, redefine the standard OData service that’s being used by the app you want to extend, and add custom entities or add fields to existing entities.
Redefining a Standard OData Service
In this example, you redefine a standard OData service and add custom fields to the existing entity:
Figure 4-25. Creating a new OData project
Figure 4-26. Redefining the standard OData service
Figure 4-27. Enter the OData service name
Instead of creating a completely new OData service, you can append additional fields onto the DDIC structure the entities are using. Then use the BAdls to update the OData model provider and data provider classes to add the fields to the standard OData service (see Figure 4-28).
Figure 4-28. Standard BAdls for extending OData model provider and data provider classes
Figure 4-29. Importing entity sets from the standard OData service
Figure 4-30. Appending custom fields to the standard DDIC structure
Figure 4-31. Give a name for the structure to append
Figure 4-32. Add your custom fields to the structure
Figure 4-33. Add your custom fields to the OData entity
Figure 4-34. Fields are now available in the property list
Now you can see the two new fields appended to your entity (see Figure 4-35).
Figure 4-35. The new fields are appended to the entity
Figure 4-36. You can see the data provider and model provider class on the right
Figure 4-37. Redefining the inherited method
Figure 4-38. Redefined method POLIST_GET_ENTITYSET
Figure 4-39. Custom code to fill the additional fields in the OData service
Test the OData service either from /IWFND/MAINT_SERVICE or directly in the browser (see Figure 4-40). Your code has appended the two new fields to the entity, and the data is updated in the response.
Figure 4-40. OData service response with the new fields and values
To learn more about standard Fiori apps such as packages, OData services, BAdl implementations, and UI5 component names, you must either manually search SICF, SEGW, /IWFND/MAINT_SERVICE, and so o n or—the easy way—go to Fiori online apps reference library at https://fioriappslibrary.hana.ondemand.com/sap/fix/externalViewer. Here you can search for any of the Fiori UI5 apps to find the details required for configuring and extending the app (see Figure 4-41).
Figure 4-41. Fiori reference library entry for Track Purchase Order
On the Configuration tab, you can see the BSP name for Track Purchase Order (see Figure 4-42).
Figure 4-42. BSP name
Similarly, you can see all the extension point names for the app. To view the extensibility documentation, click the Read More link (see Figure 4-43).
Figure 4-43. Extension details for the Track Purchase Order app
Here you find even more detailed information about the BAdls, extension points, and so on (see Figure 4-44). Basically, the Fiori reference library is a combination of the SAP Help page and the generic information about each standard Fiori app, all in one place. Because the total number the Fiori apps is growing every month, manually searching for the details of each app’s configuration in the Gateway and back-end server is no longer an easy task.
Figure 4-44. Detailed extension document
Extending the Fiori Standard Application UI in Eclipse
Now that you have a custom OData service, it’s time to create a Fiori extension project from your previously imported standard app. Wave 1 of the Fiori apps did not include the extension project concept. So, in Wave 1, you had to modify the standard code according to your needs and then upload it—a tedious task. From Wave 2 on, SAP Fiori has an enhancement framework implemented in the app source code that lets you enhance, modify or replace any view or controller of the standard app. Here are the steps:
Creating a Fiori Extension Project
Figure 4-45. Creating an extension project
Figure 4-46. Give the extension project a name
Figure 4-47. Metadata structure
At runtime, how does an extended app recognize its parent app? If you look closely at the extended app’s folders, you don’t see any of the standard app’s views or code. The idea behind the extended app is that at runtime, it loads the parent app’s source code; and wherever you have extended the app with custom code, it adds that custom code to the <Core:ExtensionPoint/> tag in the standard code or replaces the entire view with your custom view. In order for the extension app to get the parent app’s source code, you need to specify the path of the standard app in the extended app’s Component.js file under jQuery.sap.getModulePath. For example, the name of the BSP app of your standard app is mm_purord_tpo (see Listing 4-2); you must include that name so the extended app can load the parent app at runtime.
Figure 4-48. OData service configuration
Adding Extensions to the Project
Figure 4-49. Creating an extension in the project
Figure 4-50. Modifying thef S2 view
Figure 4-51. Replacing the view code
Figure 4-52. Component.js file with view-replacement code
In addition to the change in Compnent.js, you can see that an additional file has been created in the view folder, named S2Custom.view.xml (see Figure 4-53). In the case of a view extension, the file that’s created is a fragment. Fragments can be dynamically called into the <CoreExtensionPoint/> tag of the view you wants to extend. In S2Custom.view.xml, you add the two fields you get from the OData stream to the existing List control in the UI.
Figure 4-53. Extended a view for the standard S2 view
Figure 4-54. Modifying POItem.view
Figure 4-55. Hiding delivery_form from the view
You can see the changes being made in Component.js. If you modify a control, a separate file is not generated; instead, the property of the control to be modified is defined in Component.js. In this case, it is under sap.ui.ViewModifications, and the form’s Visible property is made false (see Figure 4-56).
Figure 4-56. Component.js updated with the view-modification code
Figure 4-57. Modifying the S3 view
Figure 4-58. Extending the detailsHeader of the S3 view
For the extension, the Component.js file is modified (see Figure 4-59).
Figure 4-59. Component.js updated with the view-extension code
Figure 4-60. detailsHeader fragment file
Uploading the Extension Project to the Gateway Server
You have now made all the modifications. It’s time to upload the file to the front-end server. Follow these steps:
Figure 4-61. Enter the name of the app you are uploading
Figure 4-62. Uploading the UI5 code to the Gateway server
Figure 4-63. Specify the package for the app
Figure 4-64. Enter a workbench request for creating the BSP app
Figure 4-65. Security warning from the system regarding accessing system files
Now you can see the uploaded app service in the SICF t-code (see Figure 4-66).
Figure 4-66. SICF with the service activated for the BSP app
Figure 4-67. Creating a new launchpad in LPD_CUST
Figure 4-68. Ignore the namespace warning
Table 4-1. Parameter Values to Create a New Launchpad in LPD_CUST
Field |
Value |
---|---|
Link Text |
PO Track Extended |
Description |
Purchase Order Tracking Extended |
Application Type |
URL |
URL |
/sap/bc/ui5_ui5/sap/zpo_trck_ext |
Application Alias |
zpo_trck_ext (any name you want) |
Additional Information |
SAPUI5.Component=ui.s2p.mm.purord.tracking.TrackPurchaseOrder_v2Extension |
Figure 4-69. Creating a new app in the new launchpad
You can get the value for the Additional Information field from the app source code (see Figure 4-70).
Figure 4-70. Value for the Additional Information field in the LPD_CUST app
Creating a Custom Tile in the Fiori Launchpad
Log in to the Fiori launchpad designer (see Figure 4-71). To add a custom tile to the launchpad, you need to create a new catalog and add your custom app. Follow these steps:
Figure 4-71. Creating a new catalog in the launchpad designer
Figure 4-72. Assign a unique ID for the catalog
Figure 4-73. Creating a tile for the new catalog
Figure 4-74. Choose App Launcher – Static
Figure 4-75. Static tile configuration for the extended Track Purchase Order app
Figure 4-76. Creating a target mapping
Figure 4-77. Target-mapping configuration for the extended Track Purchase Order app
The catalog setup is complete in the Fiori launchpad, but in order for end users to access these tiles, you must assign them the catalog ID that you specified when you created the catalog in the launchpad designer. To assign the catalog role to the user, follow these steps:
Figure 4-78. Create a new role for the user, to assign the catalog
Figure 4-79. Adding the catalog ID to the new role
Figure 4-80. Enter the Catalog ID created in the launchpad designer
Figure 4-81. Map the role to the end user
Adding a Custom Tile to the Home Page
When the user logs in to the Fiori launchpad (see Figure 4-82), they need to be able to access the tile you added to the catalog assigned to the user. To add the tile to the home page, follow these steps:
Figure 4-82. Tile Catalog on the end user’s home page
The new tile appears in the catalog you assigned to the user (see Figure 4-83).
Figure 4-83. Selecting the custom tile for the home page
Figure 4-84. Select the group to which you want to add the tile
Figure 4-85. Creating a new group for the tile
Figure 4-86. Extended tile on the end user’s home page
Figure 4-87. Extended Track Purchase Order app
The delivery form is hidden on the Item Details screen (see Figure 4-88).
Figure 4-88. Extended Track Purchase Order app’s S3 view
In Figure 4-89, the original screen is on the left, and the modified screen is on the right. The Delivery form is hidden on the modified app.
Figure 4-89. S3 view with delivery_form hidden
Extending a Fiori Standard Application in Web IDE
Now, let’s look at how to extend the Track Purchase Order app using Web IDE. You can get a trial version of Web IDE by registering on the SAP Hana Cloud Platform at https://account.hanatrial.ondemand.com/register. Once you have registered and logged in to Hana Cloud Platform, you can access Web IDE at /subscriptions/webide. You can also install an on-premises version of Web IDE (Chapter 6 covers Web IDE in more detail).
Connecting Web IDE to Back-End Systems
Because you are using a Web IDE that is deployed on Hana Cloud Platform, you need to do two things to connect Web IDE to your SAP back-end systems:
Let’s get on with creating a new service:
Table 4-2. Hana Cloud Destination Parameter Values
Field Name |
Value |
---|---|
Name |
<ServerName> |
Type |
HTTP |
Description |
MyServer |
URL |
Your local SAP system URL, which you configured while installing the cloud connector in step 1 |
ProysType |
OnPremise |
Cloud Connector Version |
2 |
Authentication |
NoAuthentication |
Table 4-3. Hana Cloud Destination Additional Parameter Values
Field Name |
Value |
---|---|
WebIDEEnabled |
True |
WebIDEUsage |
odata_abap,dev_abap,ui5_execute_abap |
WebIDESystem |
<ServerName> |
Creating a New Extension Project in Web IDE
One of the advantages of Web IDE is that you can download and upload standard UI5 apps directly from the Web IDE interface. You can download apps directly in Eclipse; but when you upload apps, the app folder structure is not exactly the same, because the Fiori architecture is designed to run standard apps. To create an extension project, open Web IDE in the browser and then follow these steps:
Figure 4-90. Web IDE home page
Figure 4-91. Creating an extension project using Web IDE
Figure 4-92. Selecting the back-end system to choose a standard app for extension
Figure 4-93. Give the details for the extension project
Figure 4-94. Completing the creation of the extension project
Adding Extensions to the Project
After the standard app is downloaded, just as in the Eclipse version, you can create extensions. Here are the steps:
Figure 4-95. Creating an extension for the custom app
Figure 4-96. Give the extension project a name
Figure 4-97. Select the Replace View extension
Figure 4-98. Creating an extension for the S2 view
Figure 4-99. Completing the extension
Figure 4-100. Extension view for the S2 view
Figure 4-101. Layout editor for the S2Custom view
Figure 4-102. Drag and drop controls in the layout editor
Figure 4-103. Extending a view
Figure 4-104. detailsHeader extension for the S3 view
Figure 4-105. Completing the extension for the S3 view
Figure 4-106. Fragment file for the detailsHeader extension
Figure 4-107. Open the S3 extension view in the layout editor
Figure 4-108. Adding custom controls to the S3 extension view via the layout editor
Figure 4-109. Creating a Replace Service extension
Figure 4-110. Select the custom OData service from the back-end server
Figure 4-111. Component.js updated with the replaced OData service URL
Figure 4-112. Hiding a control in the view
Figure 4-113. Hiding delivery_form
Figure 4-114. Completing the extension
Figure 4-115. Component.js updated with all the extensions in the metadata: JSON
Figure 4-116. Previewing the app
Figure 4-117. Deploy the app to the ABAP repository
Figure 4-118. Select the Gateway system to deploy the app
Figure 4-119. Give the package and details for the app
Figure 4-120. Completing the deployment of the app
The next chapter covers Fiori OData customizations and NetWeaver Gateway in detail.
18.226.93.137