Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

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

Tags:
Former Member
Former Member replied

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!

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question