Many are aware of the nice feature of the SAP Gateway – Multi Origin:

Support of multiple backend systems – How to use Multi Origin Composition and Routing

And ability to dynamically calculate an alias

Dynamic System Alias Calculation Via /IWFND/ES_MGW_DEST_FINDER – SAP NetWeaver Gateway – SAP Library

But there is a way to control it from UI. In order to enable it from Fiori/UI side a special instruction should be appended to the OData service URL – “;o=<system_alias>” for specifi origin and “;mo” for multi origin support.


A lot of Fiori applications use metadata’s “sap.ca.serviceConfigs” config property to specify a service configuration details. So, common practice is to cerate an extension component and redefine that property:



{
metadata : {
config: {
"sap.ca.serviceConfigs" : [{
     serviceUrl: "<THE_OLD_URL>;mo/",//for multi origin
...

The major limitation here is that we have to hardcode origin (or multi origin flag) in the component’s code. So, why don’t we try to make it dynamic and driven by configuration property?

The most obvious place to implement it would be a component’s constructor (Sales Order Track application for example). Component’s metadata has method applySettings which extends component’s metadata with additional supplied object.


constructor: function(sId, mSettings) {
  try {
//trying to read parameters from component configuration
  if( sId && sId.componentData && sId.componentData.startupParameters && sId.componentData.startupParameters.Origin[0] )
  {
       var serviceURL;
       var origin = sId.componentData.startupParameters.Origin[0];
       if( origin === "MULTI")
       {
            serviceURL = "/sap/opu/odata/sap/SRA018_SO_TRACKING_SRV;mo/";
       }
       else
       {
            serviceURL = "/sap/opu/odata/sap/SRA018_SO_TRACKING_SRV;o=" + origin + "/";
       }
       this.getMetadata().applySettings( { metadata : {
            config: {
            "sap.ca.serviceConfigs" : [{
                 name: "SRA018_SO_TRACKING_SRV",
                 masterCollection: "SalesOrders",
                 serviceUrl: URI(serviceURL).directory(),
                 isDefault: true,
                 countSupported: false,
                 useBatch: true,
            }]}}});
  }
       cus.sd.salesorder.monitor.Component.apply(this, arguments);//calling parent's constructor to continue initialization
  } catch (e) {
       jQuery.sap.log.error("An error occured while instantiating component: " + e);
  }
},

But surprisingly it didn’t work and throws some non obvious exception. After some debugging we found out that applySettings expects a baseType property in metadata:


this.getMetadata().applySettings( { metadata : {
baseType : "cus.sd.salesorder.monitor.Component",
config: {
"sap.ca.serviceConfigs" : [{

And that little trick solved the problem.

So, now we can use extended Fiori application and specify an origin dynamically from component configuration: MULTI for multiple origin, and a name of the alias in case of particular origin.

To report this post you need to login first.

6 Comments

You must be Logged on to comment or reply to a post.

Leave a Reply