Skip to Content

How to embed mock data in a SAPUI5 mobile application


You might wonder how to create a mobile app with SAP Web IDE which contains all the data inside of it. This could be useful for example if you need to do a demo and you don’t have any connectivity with the backend server or if you simply want to test your mobile application.

Well, this is the right blog for you!

Of course there is nothing in this blog related to offline capabilities of a mobile app: what I’ll show here is just a way to create an app which contains all the data inside of it.


  • SAP Web IDE 1.10 and later (you can register at SAP HANA Cloud Platform to get your development environment)
  • Hybrid Application Toolkit 1.3.2+ downloadable from here


This is the list of all the steps we’ll go through:

  1. Create a SAPUI5 Kapsel app with SAP Web IDE
  2. Generate random data
  3. Deploy and run the app on the mobile device
  4. (Optional) Save real data to the JSON files

Let’s get started!

Create a SAPUI5 Kapsel app with SAP Web IDE

The first thing you need to do is to create your mobile application using one of the Kapsel templates provided out of the box from SAP Web IDE. For this example I’m using the SAPUI5 Master Detail Kapsel Application template.

  • Open SAP Web IDE
  • From the File menu choose New –> Project from Template
  • Select the SAPUI5 Master Detail Kapsel Application template and click on Next


  • Enter a project name and click on Next


  • Select the Service Catalog data source and the destination you have configured for your service: in my case it’s named “es1“. You might be requested to enter the credentials for accessing the service catalog on the gateway.
  • Specify the service you want to access by selecting it in the dropdown list and click on Next.


  • Enter the necessary information you want to get from the service and click on Next (i.e. this is what I want to display for this exercise):



  • Click on Next
  • Click on Finish
  • Run the application in the Web Preview to check that all works fine


Generate random data

We need to generate mock data so that this app can work with it.

  • Open the model folder located under the project we have just created in SAP Web IDE
  • Right click on the metadata.xml file and select Edit Mock Data


  • In the new screen, select one by one all the collections displayed in the list and for each one click on the Generate Random Data button


  • For each one of the collections, 10 records will be randomly generated and the grid will be automatically populated with the new data. You can also change some data, if you want, and add new records to the existing list
  • Once you have created the mock data for all the collections click on OK
  • In the model folder you will find as many files as the collections you have


Let’s enable now the application to take always mock data. The easiest way to do it is to change the init function in the Component.js file.

  • Open the Component.js file and locate the init function
  • Remove completely the if statement you can find starting at line 81 (just after the declaration of the oModel variable)


  • Replace the entire statement with the following code:

var sServiceUrl = mConfig.serviceConfig.serviceUrl;
  oModel = new sap.ui.model.odata.ODataModel(sServiceUrl, true);


This code will force the application to use always the mock server with the JSON files we have just generated

  • Save the Component.js file and run the application again in the desktop to check that it’s now taking data from the mock server


Deploy and run the app on the mobile device

Now you can mobilise the entire application.

  • Configure your Project Settings –> Device configuration by specifying the application name, a description, the application ID and the version


  • Choose the platforms which you want to deploy for and click on Save


  • Start your Hybrid Application Toolkit and deploy the app to your local machine


  • When the deployment finishes, select the index.html file and run the app on your Android/iOS emulator/device.


  • You should be able to use the app now without any connection to the outside world.


(Optional) Save real data to the JSON files

We are using now random generated data. What about if, for some of the collections, we want to use JSON files populated with real data coming from the service? We can do it using a nice trick.

complete_URL_to_the_service + collection_name + “Collection?$format=json”

For example, let’s take the Product.json file, so your final URL will be$format=json

  • Copy this URL and paste it in a new tab of your browser, you should get the following result


  • Select the entire content of the page, i.e. by pressing CTRL+A on Windows or COMMAND+A on Mac, and copy it in the clipboard
  • Go back on SAP Web IDE
  • Double click on the Product.json file to open it, select the entire content of the file, delete it and paste here the content copied in the clipboard


  • Click on Edit –> Beautify to beautify the JSON file. It will be e


  • The new file is not yet ready, we need to do some adjustments to it. Remove the first 2 rows and part of the third just before the first open square bracket “[


  • Go at the end of the file and remove the last 2 rows, that is all the characters after the last closed square bracket “]


  • Beautify once again your code
  • Save the file
  • Retest your application.


You have done it!

You must be Logged on to comment or reply to a post.
  • Hi Simmaco ,

    this is so cool ..

    What about adding a button to switch between mockdata and backend data ?

    This way you can demo your app live or from the mock data if no connection is available .

  • Hi Simmaco,

    I created SAP Fiori demo app with mock data, its working with in SAP WebIDE(Run with mockdata),

    But I want to run this app in FLP with mock data for demo purpose,

    So I did as you said in component.js file but still I I am not the data binding..

    Mock Data.jpg

    Component.js File:"Sales_Oder_Mock_Data.Component");"Sales_Oder_Mock_Data.MyRouter");

    sap.ui.core.UIComponent.extend("Sales_Oder_Mock_Data.Component", {

      metadata: {

      name: "Sales_Oder_Mock_Data",

      version: "1.0",

      includes: [],

      dependencies: {

      libs: ["sap.m", "sap.ui.layout"],

      components: []


      rootView: "Sales_Oder_Mock_Data.view.App",

      config: {

      resourceBundle: "i18n/",

      serviceConfig: {

      name: "SALESORDERXX",

      serviceUrl: ""



      routing: {

      config: {

      routerClass: Sales_Oder_Mock_Data.MyRouter,

      viewType: "XML",

      viewPath: "Sales_Oder_Mock_Data.view",

      targetAggregation: "detailPages",

      clearTarget: false


      routes: [{

      pattern: "",

      name: "main",

      view: "Master",

      targetAggregation: "masterPages",

      targetControl: "idAppControl",

      subroutes: [{

      pattern: "{entity}/:tab:",

      name: "detail",

      view: "Detail"


      }, {

      name: "catchallMaster",

      view: "Master",

      targetAggregation: "masterPages",

      targetControl: "idAppControl",

      subroutes: [{

      pattern: ":all*:",

      name: "catchallDetail",

      view: "NotFound",

      transition: "show"





      init: function() {

      sap.ui.core.UIComponent.prototype.init.apply(this, arguments);

      var mConfig = this.getMetadata().getConfig();

      // Always use absolute paths relative to our own component

      // (relative paths will fail if running in the Fiori Launchpad)

      var oRootPath ="Sales_Oder_Mock_Data");

      // Set i18n model

      var i18nModel = new sap.ui.model.resource.ResourceModel({

      bundleUrl: [oRootPath, mConfig.resourceBundle].join("/")


      this.setModel(i18nModel, "i18n");


      // ************************************************************************

      var sServiceUrl = mConfig.serviceConfig.serviceUrl;

      // //This code is only needed for testing the application when there is no local proxy available

      // var bIsMocked ="responderOn") === "true";

      // // Start the mock server for the domain model

      // if (bIsMocked) {

      // this._startMockServer(sServiceUrl);

      // // this.start(sServiceUrl);

      // }

      // // Create and set domain model to the component

      // var oModel = new sap.ui.model.odata.ODataModel(sServiceUrl, {

      // json: true,

      // loadMetadataAsync: true

      // });

      // oModel.attachMetadataFailed(function() {

      // this.getEventBus().publish("Component", "MetadataFailed");

      // }, this);

      // this.setModel(oModel);

      // var sServiceUrl = mConfig.serviceConfig.serviceUrl;


      var oModel = new sap.ui.model.odata.ODataModel(sServiceUrl, true);


      // *****************************************************************************

      // Set device model

      var oDeviceModel = new sap.ui.model.json.JSONModel({


      isNoTouch: !,


      isNoPhone: !,

      listMode: ? "None" : "SingleSelectMaster",

      listItemType: ? "Active" : "Inactive"



      this.setModel(oDeviceModel, "device");



      _startMockServer: function(sServiceUrl) {


      var oMockServer = new sap.ui.core.util.MockServer({

      rootUri: sServiceUrl


      var iDelay = +("responderDelay") || 0);


      autoRespondAfter: iDelay



      oMockServer.simulate("model/metadata.xml", "model/");


      debugger;"Running in demo mode with mock data.", {

      duration: 4000



      getEventBus: function() {

      return sap.ui.getCore().getEventBus();



    please help me on this...

    thank you in advance

    Mock Data.jpg
  • Dedicated Kapsel templates are no more supported by HAT Team. For more info, see