cancel
Showing results for 
Search instead for 
Did you mean: 

SMP kapsel offline store requests offline store

chinna_babu2
Active Participant
0 Kudos

Hi Experts,

I am using Kapsel oData for offline to read list and detail records using below code to create the offline stores.


    var properties = {

        "name": "ListStore",

        "host": applicationContext.registrationContext.serverHost,

        "port": applicationContext.registrationContext.serverPort,

        "https": applicationContext.registrationContext.https,

        "serviceRoot" :  applicationContext.applicationEndpointURL+"/ZLISTSER_1_SRV",

        "streamParams" : "custom_header=Authorization:" + authStr + ";",

        "definingRequests" : {

        "ListDR" :

                {

                    "url" : "/IsListSet?$filter= IvType eq ''&$expand=NavList"

                }

        }

    };

    stores[0] = sap.OData.createOfflineStore(properties);

    stores[0].open(function(){

              sap.OData.applyHttpClient();

               var url = applicationContext.applicationEndpointURL+"/ZLISTSER_1_SRV/IsListSet?$filter= IvType eq ''&$expand=NavList";

               var oHeaders = {};

               oHeaders['Authorization'] = authStr;

               var request = {

                   headers : oHeaders,

                   requestUri : rUrl,

                   method : "GET"

               };

               OData.read(request,readSuccessList, errorList);            

    }, errorOpenStore/*, options*/)


// Iterate through list and call  open store for details

function readSuccessList(data, response) {

    var isApplyOffline = false;

    var resultsLength = data.results[0].NavList.results.length;

    for(i =0;i<data.results[0].NavList.results.length;i++){

        if(i === resultsLength )

            isApplyOffline = true;

        openStoreDetail(data.results[0].NavList.results[i].zznum, isApplyOffline);

     }

}


// Open store for Details

function openStoreDetail(lnum, isApplyOffline) {

    var properties = {

        "name": "DetailOfflineStore",

        "host": applicationContext.registrationContext.serverHost,

        "port": applicationContext.registrationContext.serverPort,

        "https": applicationContext.registrationContext.https,

        "serviceRoot" :  applicationContext.applicationEndpointURL+"/ZLISTSER_2_SRV",

        "streamParams" : "custom_header=Authorization:" + authStr + ";",

        "definingRequests" : {

            "detailDR" :

            {

                "url" : "/EsHeaderSet('" + lnum + "')"

            }

        }

    };

    stores[1] = sap.OData.createOfflineStore(properties);

    stores[1].open(function(){

                    if(isApplyOffline)

                        sap.OData.applyHttpClient();

                   }, errorDetailStore/*, options*/)

   

}

Store is opening for List successfully and when trying to open the store for details records (has 10 records) only one time store is opening for record, for the remaining it seems it is calling offline store.

Is it because serviceRoot is same? here is the error when I called the openStoreDetail function

"[-10001] An error occurred executing SQL statement: SELECT longValue FROM LODATA_SYS_PROPERTIES WHERE propertyID=?.  Reason: -141 (ERROR) %1:LODATA_SYS_PROPERTIES."

How can I get all the details downloaded and stored in offline store.

Please suggest how to achieve this with offline store.

Regards,

Murthy

Accepted Solutions (1)

Accepted Solutions (1)

midhun_vp
Active Contributor

Hi Narasimha,

You are using different base urls (../zlistser_1_srv, .../zlister_2_srv) I think this is not allowed.

You could use integration gateway  (free component that comes with SMP) to mash up these different services to create a single service as mentioned in this blog: . In this example I am using different data sources but in your case you should use different odata sources to get a single Odata url then define it as backend while configuring app in SMP.

May be Dan also could give more information on this.

Regards, Midhun

SAP Technology RIG

Dan_vL
Product and Topic Expert
Product and Topic Expert
0 Kudos

There is an example here of opening multiple stores but in this case they are both using the same service.

There is also an example called offline and online in one app that uses two different backend connection names.

Could you use a filter for the second store rather than specifying multiple defining requests each with a record ID?  The store is populated from the defining requests when it is opened the first time.  If you open the store a subsequent time, I don't think you can modify the defining request to add more records.  I believe you can specify a parameter during the refresh call but that would likely be to refresh a subset not to superset of the defining requests.

Midhun's suggestion also sounds good. 

Dan van Leeuwen

chinna_babu2
Active Participant
0 Kudos

Thanks Midhun & Dan,


Will try if I can use integration gateway approach.


But the problem is data from Gateway server comes from different services and for each service I will need to call the few more services to get the detail records.


For example I have two Services ZCUSTOMER_SRV (Read customer and Distributors), ZVENDOR_SRV(Read Vendors).

After got the header data for Customers, Distributors and Vendors I need to call ZADDR_SRV(Address), ZBANK_SRV (Bank Details) services for all Customers, Distributors and Vendors.


I am using the below approach to get the list of Customers, Distributors and Vendors.

For List:

Step1:

     var properties = {

          "serviceRoot": applicationContext.applicationEndpointURL+"/ZCUSTOMER_SRV"

     }

     definingRequest :{

          "Customers":"/GetCustomers?$expand=NavCustomerList",

          "Distributors":"/GetDistributors?$expand=NavDistList",

     }

     store.openStore -- for customers, distributors.

     oData.read(request, function(data){customerData = data})

     oData.read(request, function(data){distributorData = data})

Step2:

     var properties = {

          "serviceRoot": applicationContext.applicationEndpointURL+"/ZVENDOR_SRV"

     }

     definingRequest :{

          "Vendors":"/GetVendors?$expand=NavVendorList",

          "Distributors":"/GetDistributors?$expand=NavDistList",

     }

     store.openStore -- for customers, distributors.

     oData.read(request, function(data){vendorData = data})


For Details:


Step3:

     if(customerData && distributorData && vendorData) // Available

     {   

          // to get the details for each  loop through the data and defineRequest

          for(i = 0; i < customerData.length; i++)

          {

               properties.defineRequest['\"custDR'+customerData[i]+'\"'] = "/GetDetail?$cnum eq '"+customerData[i].zno+"'";

               properties.defineRequest['\"DistrDR'+customerData[i]+'\"'] = "/GetDetail?$dnum eq '"+customerData[i].zno+"'";

               properties.defineRequest['\"VendorDR'+customerData[i]+'\"'] = "/GetDetail?$vnum eq '"+customerData[i].zno+"'";

          }

          store.openStore -- for Vendors.

         

     }

This approach is creating the offline store but at times failing. I don't know if this approach works when  need refresh the store with updated data.

I am not sure if I can apply the approach from Getting Started with Kapsel - Part 10 -- Offline OData (SP09+)

Regards,

Murthy

   

chinna_babu2
Active Participant
0 Kudos

often I get below error when opening multiple stores, either as an array of stores or with store object.

[-10067] Could not create the store.  Reason: -685 (ERROR) %1:START DATABASE.

like below

store.open( for customer service )

store.open( for vendor service )

store.open( for partner service)

( or )

stores[0].open( for customer service )

stores[1].open( for vendor service )

stores[2].open( for partner service)

any Idea whey does the above error throws?

Regards,

Murthy

Dan_vL
Product and Topic Expert
Product and Topic Expert
0 Kudos

I just updated the question and answer section of this document with the below content.

Question

How many Offline Stores can be open at the same time? The following error is occurring when opening five offline databases. [-10067] Could not create the store. Reason: -685

Answer

There is a limit to the total number of Ultralite databases that can be running concurrently as of SP09, and each offline store has 2 databases (the offline store and the request queue). Currently on a device, the limit is 8 databases which means that a maximum of 4 offline stores can be open at the same time.



Hope that helps,


Dan van Leeuwen

chinna_babu2
Active Participant
0 Kudos

Thanks Dan, this helped a lot. Will close the thread once I tried the above suggestions or I will update the approach I followed.

Regards,

Murthy

Answers (1)

Answers (1)

chinna_babu2
Active Participant
0 Kudos

I changed the method to define individual request for each detail record as below

  1. function openStoreDetail(data, isApplyOffline) { 
  2.     var properties = { 
  3.         "name": "DetailOfflineStore"
  4.         "host": applicationContext.registrationContext.serverHost, 
  5.         "port": applicationContext.registrationContext.serverPort, 
  6.         "https": applicationContext.registrationContext.https, 
  7.         "serviceRoot" :  applicationContext.applicationEndpointURL+"/ZLISTSER_2_SRV"
  8.         "streamParams" : "custom_header=Authorization:" + authStr + ";"
  9.         "definingRequests" : { 
  10.             "DetailRecord1" : "/EsHeaderSet('" + record1 + "')" ,
  11.             "DetailRecord2" : "/EsHeaderSet('" + record2 + "')" // and so on
  12.         } 
  13.     }; 

Can anyone advise if this is the correct way to store? I will mark this thread answered if my testing successful.

Regards,

Murthy