cancel
Showing results for 
Search instead for 
Did you mean: 

How to create mutiple Offline Stores in SAP Mobile App

chetan2992
Explorer
0 Kudos

Hello Experts,

I want to create to two different offline stores, since i am using two different OData services in my mobile Application.

Here is my below code which i used to create Offline stores (sap-mobile-hybrid.js).

var stores;
openStore: function () {
        jQuery.sap.require("sap.ui.thirdparty.datajs");

        var properties = [{
            "name": "ZABC",
            "host": sap.hybrid.kapsel.appContext.registrationContext.serverHost,
            "port": sap.hybrid.kapsel.appContext.registrationContext.serverPort,
            "https": sap.hybrid.kapsel.appContext.registrationContext.https,
            "serviceRoot": fiori_client_appConfig.appID + "_abcSet/sap/ZABC/",
            "definingRequests": {
                "abcSet": "/abcSet"
            }
        }, {
            "name": "ZXYZ",
            "host": sap.hybrid.kapsel.appContext.registrationContext.serverHost,
            "port": sap.hybrid.kapsel.appContext.registrationContext.serverPort,
            "https": sap.hybrid.kapsel.appContext.registrationContext.https,
            "serviceRoot": fiori_client_appConfig.appID + "_xyzSet/sap/ZXYZ/",
            "definingRequests": {
                "abSet": "/ab",
                "pqSet": "/pq"
            }
        }];

        for (var i = 0; i < properties.length; i++) {
            stores = sap.OData.createOfflineStore(properties[i]);

            var openStoreSuccessCallback = function () {
                sap.OData.applyHttpClient();
                sap.hybrid.startApp();
            }
            var openStoreErrorCallback = function (error) {
                alert("An error occurred" + JSON.stringify(error));
            }

            stores.open(openStoreSuccessCallback, openStoreErrorCallback);
        }
    }

The issue i am currently facing is that the offline stores are getting created but duplicate views are also getting created.

For Example : If am using Table control in a page and if i scroll down the table list, another Table control has already been created in the same page.

Kindly Please help me is these issue.

View Entire Topic
LudoNoens
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Chetan,

A similar query was posted here: https://blogs.sap.com/2018/05/22/creating-an-offline-crud-hybrid-mobile-app-in-sap-web-ide-full-stac...

I recommend creating 2 separate openStore functions with separate properties and defining requests.

Besides that, your code handles the openStoreSuccessCallback twice, resulting in duplicate calls to applyHttpClient() and startApp(). In the first success callback you could call the 2nd openStore function (just a suggestion).

Regards,
Ludo