Handling Startup Parameters
Handling of startup parameters that are encoded in the URL.
Passing Startup Parameters Dynamically with JavaScript
An app can dynamically pass parameters to another app using the CrossApplicationNavigation service. The following code snippet shows an example:
var href_For_Product_display = ( sap.ushell && sap.ushell.Container &&
sap.ushell.Container.getService("CrossApplicationNavigation").hrefForExternal({
target : { semanticObject : "Product", action : "display" },
params : { "ProductID" : "102343333", SupplierId : "90210" }
})) || "";
Receiving Startup Parameters Dynamically with JavaScript
Startup parameters are received by an embedded component by calling the getComponentData method, which returns a startupParameters member. The following code snippet shows an example:
sap.ui.core.UIComponent.extend("AppNavSample.Component", {
...
createContent : function() {
/*
* getComponentData() returns an object like { startupParameters : { AAA : ["BBB"], DEF: ["HIJ","KLM"] } }
* NOTE: parameters values are passed via arrays
*/
var oComponentData = this.getComponentData();
jQuery.sap.log("app was started with parameters " +
JSON.stringify(oComponentData.startupParameters || {} ));
...
}
});
Consuming Startup Parameters from Inside an Embedded View
For views created by the SAPUI5 routing framework or directly from within the component, you can locate and identify the component using getOwnerIdFor. The following code snippet shows an example:
// view controller.
getMyComponent: function() {
"use strict";
var sComponentId = sap.ui.core.Component.getOwnerIdFor(this.getView());
return sap.ui.component(sComponentId);
}
onCreate : function() {
…
var oStartupParameters = this.getMyComponent().getComponentData().startupParameters;
}
...
For more information, see sap.ui.core.Component.
Other Sources of Startup Parameters
To set startup parameters for an app, the following options exist:
- Passing the startup parameters dynamically from the source app as described above.
- Setting the startup parameters in the configuration of a navigation target in transaction LPD_CUST, see Customizing Navigation Targets.
- Defining the startup parameters in configuration (target mapping).
- User enters them manually in the URL.
Passing Query Parameters in a Stand-alone Index Page
If you use a stand-alone index page for testing your app in a local environment, you can pass the query parameters to the component as shown in the following example:
<head>
…
<script>
var oStartupParameters = jQuery.sap.getUriParameters().mParams;
var oComponent = sap.ui.getCore().createComponent({
name: "sap.samples.SampleComponent",
settings: {
componentData: { startupParameters: oStartupParameters }
}
});
new sap.ui.core.ComponentContainer({
component: oComponent
}).placeAt("content");
</script>
</head>
<body>
<div id=”content”/>
</body>