Skip to Content
avatar image
Former Member

Kapsel Offline OData plugin issue when retrieving number of entries in a list

Hello everyone,

I'm developing a Cordova application with Kapsel and SAPUI5. using the new OData Offline plugin from Kapsel as the Offline storage.

I have sap.m.Text element where I want to show the number of entries from a list:

var productQuantity = new sap.m.Text();


I bind the value assigning a formatter:

productQuantity.bindText("idProduct", productCount);


And here's the formatter code, that returns the number of entries from the /Products list:

function productCount(oValue) {
        var oBindings = this.getModel().bindList("/Products");
        return oBindings.getLength();
}

Everyting works as intended when the device is online, the issue is when offline, the product list loads fine, but the counter always shows the number 10, which is not the same number of products in the list.

Is this count operation possible with the Offline OData plugin for Kapsel? Or there's another way?

Regards,

Kenyon Tu

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    Feb 26, 2015 at 02:45 PM

    I was able to solve the problem by myself. Instead of using the "hack", described in the question, I replaced that with a simple odata count request:

    var username = applicationContext.registrationContext.user;
    var password = applicationContext.registrationContext.password;
    var connectionId = applicationContext.applicationConnectionId;
    
    
    var oHeaders = {};
    oHeaders['Authorization'] = "Basic " + btoa(username + ":" + password);
    oHeaders['X-SMP-APPCID'] = connectionId;
    
    
    var request = {
        headers: oHeaders,
        requestUri: url,
        method: "POST"
    };
    
    
    var url = applicationContext.applicationEndpointURL + "/Products/$count";
    
    
    var successCallback = function(data, response) {
      var count = parseInt(data);
      this.getView().byId("viewIdHere").setText(count);
    }
    
    
    OData.read(request, successCallback, errorCallback);
    

    Thanks for the help! 😊

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 15, 2015 at 09:14 PM

    Can you please sure with me all the steps so I can reproduce this. So here is what I would like:

    1. The version and SP of the SMP server and SDK

    2. The Offline oData configuration file if you imported one through eh Cockpit

    3. What does the OData End point looks like?

    4. What Mobile device OS you tested this with

    5. If you can create a sample project that has this issue reproduced and share it, that would be great.

    Thank you

    Add comment
    10|10000 characters needed characters exceeded