Skip to Content

When you are working in an offline store scenario and experiencing some problems , you report it to developer and he/she asks for client database access for further troubleshooting/analysis.

Client Database upload policy” feature has been available since a while in SAP Cloud Platform Mobile Service (SAP CPms) for Developers and Operations cockpit. Once this feature is enabled, user can upload offline store from mobile application to SAP CPms and then administrator/developer can download it for troubleshooting.

For this blog, i will show how you can make a REST API call in order to upload client database to SAP CPms.

 

 

Pre-requisites:

  • On-board a hybrid/native application in SAP CPms cockpit
  • Enable Client database upload policy feature
  • Developer needs to implement this feature in application project

How to get started?

  1. To understand how this feature can work, i am using existing project at this page (HTML5/iOS) . Download, extract and open it with Xcode.
  2. On-board an application in SAP CPms cockpit with application ID as : com.sap.mit.advanced.offline
  3. Click on plus icon ‘+’ (under Assigned Features) to add a Feature to application,select Sample OData Service,  Save it.
  4. Click on Security , select configuration as Basic (since i want to test this upload feature via REST client, to make it simple, i chose Basic) , Save it

   5. Click on Client Policy, select “Enable Database Upload Policy” , you can provide value for Days and DB size as per your needs. Save it.

 

6. In your Xcode, open SAP MIT Offline> Staging>www >serverContext.js file, change authentication flow from SAML to Basic (as i already mentioned in step#4) , code should look like this:

/* exported
  appId,
  serverContext
*/

// The application ID is the unique identifier of the application.
// It must be the the same ID as on the server, but it may be different
// from the bundle identifier of your application.
var appId = "com.sap.mit.advanced.offline";

//@Advanced: Comment in and adjust the following section
var serverContext = {
    "serverHost": "hcpms-xxxxtrial.hanatrial.ondemand.com",
    "https": "true",
    "serverPort": "443",
    //"auth": [ { "type": "saml2.web.post" } ],
    // This prevents the default behavior of refreshing the SAML session
    // when the app is resumed. Otherwise the app would not be able to start
    // in without a network connection.
    // We will need to make sure that the SAML session is available before we
    // request online data from the server, but only when we manually trigger
    // HTTP requests. Offline data synchronization via the sap.OData APIs
    // takes care of this automatically.
    // See the errorCallback() in crud.js and the refresh() and flush() methods
    // in offline.js for more information.
    // 
    // Please note that this is specific to SAML authentication and would not
    // be required e.g. with Basic authentication.
//    "refreshSAMLSessionOnResume": "skip"
    "user": "",
    "password": ""

};
​

7. In your Xcode, open SAP MIT Offline> Staging>www >offline.js file , uncomment section under openStore function

 

openStore = function() {
    console.log("MIT: In openStore");
    showInfo("Opening store...");
    
//@Advanced: Comment in and adjust the following section
//    // Defining requests determine what data is going to be
//    // made available offline. In this case, both the whole
//    // sales order and sales order items are taken offline,
//    // but not the other entity sets.
//    // While you can use OData system query options with the defining
//    // requests, you should avoid $expand, because this makes delta
//    // queries rather inefficient. However, you can run $expand
//    // queries against the offline store, just like any other query.
    var properties = {
      "name": "mitOfflineStore",
      "host": applicationContext.registrationContext.serverHost,
      "port": applicationContext.registrationContext.serverPort,
      "https": applicationContext.registrationContext.https,
      "serviceRoot" :  "com.sap.edm.sampleservice",
      
      "definingRequests" : {
        "SalesOrders"  : "/SalesOrderHeaders",
        "SalesOrderItems" : "/SalesOrderItems"
      }
    };   

 

8. Build and Run your app, and you must go through screens like Logon (1), setpasscode (2), successful Logon message (3),

Click on READ > you will see data coming from sample odata service in online mode now click on Back icon (4)

Click on Open Offline Store at (3) , you will see a message like store opened as (5) and now click on Read on same screen, here (6) data is coming from offline store.

 

 

 

9. Next task is to find out client database/offline store UDB file(s) , since i am testing this application in iOS simulator, i can find its path via Activity Monitor

Search with “mit” , double click process name , Navigate to Open Files and Ports, scroll down till last.

Look for this path in finder and copy this UDB file to some location.

10. Open any preferred REST client (example),  make a POST call

Method POST
URL https://hcpms-xxxtrial.hanatrial.ondemand.com/mobileservices/application/<appid>/offlinestoreupload/v1/runtime/application/<appid>/device/<registrationID>
Headers

Authorization : Basic <SAP CPms user credentials>

Content-Type:multipart/form-data

BODY

select it as Form

give some name as localstore

select File

point it to UDB file copied as per step#9

Request should be like below: On successful you would get 204 No content .

 

11. To verify whether it has been upload to SAP CPms cockpit, navigate to Application, click on Offline

 

The developer analyzes the database file to solve a problem encountered by the user. The file is deleted from the server when the policy time limit has expired.

To analysis this UDB file, you can install SAP SQL Anywhere client on your machine , connect via UltraLite> username (dba) password (sql) > you may need to provide encryption key if DB is encrypted

 

Wanna test it from a hybrid app, check this out.

 

I hope this helps.

Jitendra Kansal

Product Management, SAP Cloud Platform User Experience
SAP SE

 

To report this post you need to login first.

1 Comment

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

Leave a Reply