Cross Application Navigation between SAPUI5 applications
At SAP Inside Track Hamburg 2016 together with Remo Bettin we demonstrated during a short lightning talk how to do Cross Application Navigation between different applications on the Fiori Launchpad.
While this topic is covered in SAPUI5 help it is still not so easy to implement it. Therefore we built a small demo application in order to demonstrate how to use it.
Based on the entities of the Northwind OData Service we created four separate SAPUI5 Applications, one for orders, others for the corresponding customers and suppliers of the orders shown in the Orders app. The last application we used is based on the categories entity of the Northwind service.
All these applications are added to the Fiori Launchpad in the HANA Cloud Platform (which is named flpnwc there and available as a subscription in the HCP account).
Picture 1: Fiori Launchpad in HCP showing the applications
In order to be able to use cross app navigation all applications need to be assigned to intents. The intent consists of a semantic object and an action on this object. For our applications we used the entity name as semantic object and all applications use the “display” action to display some data. The semantic object is declared in the manifest.json from the SAPUI5 app.
Picture 2: Navigation properties in manifest.json
Once an application is reached it uses inner app navigation to find the correct route to a view.
The following example shows the routes in the supplier app. Here to navigate to a supplier detail we use a route “Suppliers/5” in order to open the object view and show details of supplier with ID 5.
Picture 3: Routes in manifest.json
In order to navigate from one application to another in the Fiori Launchpad (FLP) we need to implement some code at the following locations:
1. The starting point of our CrossApp-Navigation is pressing on the supplier column in the Orders app. There we added the onPressSupplier-event in the column of the detail view where the supplier is shown
onPressSupplier: function(oEvent) {
var supplier = oEvent.getSource().getBindingContext().getProperty("Product/SupplierID"); // read SupplierID from OData path Product/SupplierID
var oCrossAppNavigator = sap.ushell.Container.getService("CrossApplicationNavigation"); // get a handle on the global XAppNav service
var hash = (oCrossAppNavigator && oCrossAppNavigator.hrefForExternal({
target: {
semanticObject: "Supplier",
action: "display"
},
params: {
"supplierID": supplier
}
})) || ""; // generate the Hash to display a Supplier
oCrossAppNavigator.toExternal({
target: {
shellHash: hash
}
}); // navigate to Supplier application
}
2. In the onInit-Event of the Master view of the Suppliers App we attach the event _onMasterMatched:
this.getRouter().getRoute("master").attachPatternMatched(this._onMasterMatched, this);
3. In the _onMasterMatched we read the Startup parameters where we get the Supplier ID:
_onMasterMatched : function() {
var supplierID;
var startupParams = this.getOwnerComponent().getComponentData().startupParameters; // get Startup params from Owner Component
if ((startupParams.supplierID && startupParams.supplierID[0])) {
this.getRouter().navTo("object", {
supplierID: startupParams.supplierID[0] // read Supplier ID. Every parameter is placed in an array therefore [0] holds the value
}, true);
} else {
this.getOwnerComponent().oListSelector.oWhenListLoadingIsDone.then(
function(mParams) {
if (mParams.list.getMode() === "None") {
return;
}
supplierID = mParams.firstListitem.getBindingContext().getProperty("SupplierID");
this.getRouter().navTo("object", {
supplierID: supplierID
}, true);
}.bind(this),
function(mParams) {
if (mParams.error) {
return;
}
this.getRouter().getTargets().display("detailNoObjectsAvailable");
}.bind(this)
);
}
Demonstration
Based on the entities of the Northwind OData Service we created four separate SAPUI5 Applications. In the Orders application you see a Master-Detail navigation for selecting an order and displaying the corresponding order details.
We select one order in the left master view and after that click on Customer “Vins et alcools Chevalier” with CustomerID “VINET”:
This creates the link “#Customer-display?customerID=VINET&/Customers/VINET”.
The action “display” in the application with semantic object “Customer” is invoked.
The startup parameter is “customerID=VINET”. This invokes the inner app navigation in the Customer app resolving in the URL fragment “/Customers/VINET” which is the route to the object view and shows the details view of customer “Vins et alcools Chevalier”.
Similar routing happens when clicking on the supplier in the orders app:
Question
When using the sap.ushell.services.CrossApplicationNavigation.toExternal() method you can optionally provide a component (the root component of the application). Unfortunately in the help you can’t find a hint for what this could be used. Maybe somebody knows the intent of this parameter?
Hopefully this blog post will be of some help for your implementation of Cross application navigation. In case you still have questions I would be happy to answer them if possible.
Cheers,
Mark
Really appreciate your blog. Really its helps alot.
Can you provide the manifest.json code? I have implemented same code in my system but i did not understand mainfest.json code in your blog
cross application navigation not working in my application and console did not provided any error. i did not able to figureout error..
Sorry for my late response. I did not get any notification from the new community platform...
This is the manifest.json from one of the apps.
Thanks for your excellent blog!!
On adding the code as per your blog, I get a warning as shown below. Will this cause any issue?
Hi Charles,
it is only a warning and will not cause an issue. But from a coding perspective it would be nicer to write it like the following example:
Source: https://help.hana.ondemand.com/webide/frameset.htm?6de3ec7327e0432cae87fc83f06db827.html
Thank you Mark!
now it is better to use “isNavigationSupported” instead of “isIntentSupported”.
Source: https://sapui5.netweaver.ondemand.com/#docs/api/symbols/sap.ushell.services.CrossApplicationNavigation.html#isIntentSupported
Hi Charles Muriyadan
Did you solve the warning?
If yes could you please post your code.
Hi Charles Muriyadan,
Have you resolved the warning, if so can you please share the code. I am also facing same issue here.
Hi Mark thank you for the explanation.
I am trying to use the same principles explained here to apply in SAP Portal.
When I try to get the parameters from:
var startupParams = this.getOwnerComponent().getComponentData().startupParameters;
It says that I am trying to get the parameters from something that is undefined.
Do you know if I have to define the routing in the Portal Manifest or the routing should be defined on the application that we want to read the parameters?
I think that I can't access the arguments because in the Portal each time you navigate to a new page you initialize all the applications in that page again. So I don't think that the routing happens but only the oninit function.
The thing is that I can actually navigate in the portal by using a similar implementation to what you explained above.
If you could help me it would be great! Thank you!
Hi Jose,
I do not use the SAP Portal but I think that routing is handled differently there. Maybe this help page will put you on track...
Hi Mark Teichmann
Nice blog!! This helped a lot.
But I can see in your screenshot when clicking on the supplier in the orders app, the app not only navigates to the Suppliers app and opens up the detail but also the same Supplier is selected in the master list.
I applied the same code but the order doesn't get selected in the master list. Can you share the code to implement the same.
Also, when the updateFinished method is called, it calls the first item selected and replaces the same in the detail page.
Kindly suggest a solution to the same.
Thanks
Kanika
Hi Kanika,
sorry for the late reply. We used the SAPUI5 Master-Detail Freestyle Application Template for the apps. It contains a ListSelector.js which takes care of the selection of master entry if I remember right.
Hi Mark,
Thanks,
Can I get some values back to the calling application.
when do you need values back in the calling application? Immediately when calling it or after you are finished in the called application and go back to the calling application?
Yes, Once I am finished and go back, I need to push some values to the calling application- may be some document number which I created.
The route back from your called application to the calling application is just another cross-application navigation where you can also use startup parameters to push the values.
Can't you use this mechanism to achieve what you would like to?
Hi Mark Teichmann
Thanks for your follow up.
Will check and update on the issue.
Thanks.
Hi Mark,
I have a similar requirement as you mentioned in your blog. I believe your application is doing Cross App navigation.
My requirement is I want to create a reusable Module or an Application or a Library(whichever is possible to be consumed from Fiorri Launchpad). I want to create a Module which can be integrated or plugged in by any Consuming Application deployed on FLP. I want to display the content of my module within the consuming application which is deployed in FLP.
I tried to do it using it Library . I am able to access and use the Library from Consuming application from HCP. However I cant achieve this in FLP. When I run the consuming Application which internally uses my Library, it gives me some error.
Can you suggest me some approach how to do it .
Thanks for your help.
Thanks for you blog, the navigation is working as intended! However, it is not smooth yet:
So, if the app is reached via intend-based navigation,
In case only the detail view will be displayed, loading the master view is unnecessary and causes flickering, like on a mobile device or when using the Worklist template.
To prevent this unnecessary loading step, I would have to catch startup parameters before getRouter().initialize() in Component.js. But at that point I can not navigate.
Is there any clean solution? I tried to naviagte at
Regards,
Jan
Hi Jan,
since 1.48, sap.ui.core.routing.Router.initialize(bIgnoreInitialHash?) provides the bIgnoreInitialHash parameter (see https://sapui5.hana.ondemand.com/#/api/sap.ui.core.routing.Router).
I leveraged this in the init() method inside the Component.js to decide if a startup parameter is provided and thus if the detail view or if the master view must be shown.
Coding looks like this:
Check if startup parameters are provided and and if current hash equals empty string (inner app route must take precedence over startup parameters)
Thus, main view is not loaded unnecessarily.
Best regards,
Kai
Excelent post,
Any chance to pass the parameters in some hidden way ? because to do it this mode , someone could alterer the url and see info not corresponding to the logged user.
Regards
Mark can you able to post the complete two application zip file