on 01-22-2016 7:44 AM
Hi All,
I am developing a Hybrid application using Cordova 4.2.0, SMP SDK 3 SP8 PL2,
Is it possible to open the offline store without registering moble with SMP Server?
var properties = {
host: "54.208.252.XXX",
https: false,
name: "PLANTCollection",
port: 8000,
serviceRoot: "http://54.208.252.XXX:8000/sap/opu/odata/invmsx/msalesx_srv/",
"definingRequests" : {
"PlantCollection" : "/PlantCollection"
}
};
store = sap.OData.createOfflineStore(properties);
//var options = {};
store.open(openStoreSuccessCallback, errorCallback/*, options*/);
I am getting null Receiver Error.
odata,logon both are different plugins correct, then why can't we use only odata plugin.
Thanks
Suresh
Hallo Suresh,
The offline plugin leverages specific functionality on the SMP(/HCPms) server, which is required for it to work. And thus you need to register against it.
Without the SMP / HCPms server you would have to craft something yourself, using for example one of the components of the offline plugin, the datajs (datajs - JavaScript Library for data-centric web applications - Documentation). I wouldn't recommend that path though.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
HI Vincent Weiss,
Thanks for information,
1. Means SMP Registration is mandatory to work with offline.
2.Is it possible to hide the Registration screen provided by logon plugin in Hybrid Application?
3.Is there any method in sap.Logon. to execute the registration process, so that we can hide the same and passcode also for the user.
Thanks
You could work without the Logon plugin itself. You would have to manually do a rest call to register though and feed more parameters when opening the store.
For example:
var properties = {
"name": "AirlinesOfflineStore",
"host": appContext.registrationContext.serverHost,
"port": appContext.registrationContext.serverPort,
"https": appContext.registrationContext.https,
"serviceRoot" : appContext.applicationEndpointURL,
"streamParams" : "custom_header=Authorization:Basic " + btoa('username:password') + ";custom_header=X-SMP-APPCID:" + appContext.applicationConnectionId + ";",
"definingRequests" : {
"FlightsDR" : "/FlightCollection?$format=json",
"CarriersDR" : "/CarrierCollection",
}
};
However the Logon plugin is easier. You can hide fields in the logon view. See:
http://scn.sap.com/docs/DOC-65387#custom
And if you want to modify it further the form itself is build up in LogonForm.js
So you might be able to submit the form at the end of the showScreen method in that Javascript.
The javascript is inserted in the platform folder of your cordova project when adding it to the project, not on build again. So if you have added the plugin you would have to modify the file in your platform folder structure, not the one in the plugins main folder.
However if you remove and re-add the plugin the changes are gone. And don't copy one on one the entire file between the plugins and the platform folder, they are not exactly the same.
(Cost me a few hours to find out after my app didn't run anymore, when I added "enter" to submit functionality and also clicking the labels to highlight the text input for iOS).
Thanks for help,
I observed following thing,
I have to call sap.OData.applyHttpClient(); only when device is offline, Is it right?
function deviceOnline(){
sap.OData.removeHttpClient();
}
function deviceOffline(){
sap.OData.applyHttpClient();
}
document.addEventListener("online", deviceOnline, false);
document.addEventListener("offline", deviceOffline, false);
2.I am getting data in offline for only some collections not all collections why?
3.For some collection in offline i am getting few entries
Ex: DivisionCollection totla entries are 428, i am getting 428 in online but in offline i am getting only 45 collections
var properties = {
"name": "mSalesOffline2",
"host": oService.applicationContext.registrationContext.serverHost,
"port": oService.applicationContext.registrationContext.serverPort,
"https": oService.applicationContext.registrationContext.https,
"serviceRoot" : "http://"+oService.applicationContext.registrationContext.serverHost+":"+
oService.applicationContext.registrationContext.serverPort+"/com.xxxxxx.msalesoffline/", //appId,
"definingRequests" : {
"ScopingCollection" : "/ScopingCollection",
"SalesOrgCollection" : "/SalesOrgCollection",
"DistrChannelCollection" : "/DistrChannelCollection",
"DivisionCollection" : "/DivisionCollection",
"CustomerCollection" : "/CustomerCollection" ,
"SOHeaderCollection" : "/SOHeaderCollection" ,
"QuotationHeaderCollection" : "/QuotationHeaderCollection"
}
};
// var bus = sap.ui.getCore().getEventBus();
// bus.publish("nav", "to", {
// id : "landing.LandingPage",
// });return;
var store = sap.OData.createOfflineStore(properties);
store.open(function success(){ }, function error(){});
var uri = this.applicationContext.applicationEndpointURL + "/";
var user = this.applicationContext.registrationContext.user;
var password = this.applicationContext.registrationContext.password;
var accessInfo = uri + ":" + password;
var Autho = "Basic " + btoa(accessInfo) ;
var headers = {"X-SMP-APPCID" : this.applicationContext.applicationConnectionId,"Authorization": Autho};
// Create OData model from URL
oModel = new sap.ui.model.odata.ODataModel(uri, { json:true,headers:headers,loadMetadataAsync:true});
var iOS = ( navigator.userAgent.match(/(iPad|iPhone|iPod)/g) ? true : false );
if (iOS) { //unsure why but the first call seems to be to http://sapes1 rather than https which fails.
oModel = new sap.ui.model.odata.ODataModel(uri, { json:true,headers:headers,loadMetadataAsync:true});
}
// sdOdataModel =oModel;
sap.ui.getCore().setModel(oModel,"SalesSD");
}
var jsonModel = sap.ui.getCore().getModel(modelName);
var forceLoad = false;
if(!jsonModel){
jsonModel = new sap.ui.model.json.JSONModel();
sap.ui.getCore().setModel(jsonModel, modelName);
forceLoad = true;
}
// var oModel = sdOdataModel;
// Attach the request completions
var finishRequest = function(oEv,response){
if(response)
jsonModel.setData(JSON.parse(response.body));
oModel.detachRequestCompleted(finishRequest);
finishMethod(oEv);
};
var reqFailed = function(oEv){
oModel.detachRequestFailed(reqFailed);
finishMethod(oEv);
};
oModel.attachRequestCompleted(finishRequest);
oModel.attachRequestFailed(reqFailed);
// Check if the model has data
if(forceLoad == false && replaceOld == false){
oModel.fireRequestCompleted(oModel);
}
if(this.mockdata == false ){
var request = {};
// oModel.loadData(finalUrl,{},true,'GET',false,false,mHeaders);
var oFilters = [];
if (!navigator.onLine) {
if(finalUrl.toString().indexOf('?') != -1)
finalUrl = finalUrl.split('?')[0];
}
oModel.read(finalUrl, {
async:true ,success:finishRequest,error:reqFailed});
Thanks
Suresh
Not exactly.
You can do that if you don't want to use Store functionality when you are online. However before you have all the data when offline, you have to make sure your store is refreshed with the refresh call or thanks to the refreshInterval.
See the part about Refreshing in
The cleanest way would be to always use the Store and just use the refresh and flush functionality of the Store when you want to communicate with the backend. That way you will know for sure your Store is always filled with data when the connection drops.
Thanks for quicj reply,
If i use the sap.OData.applyHttpClient(); code when the device is online then I am not getting the complete data in collections and filters also not working
oModel.read(finalUrl, {
async:true ,success:finishRequest,error:reqFailed});
Thanks
Suresh
Hi Vincent,
Now I am registering with SMP using oData.Create. I can able to successfully register.
But when i am opening offline store I am getting "null receiver" Error
var properties = {
"name": "mSalesOffline",
"host": "XX.XX.XX.XX",
"port": "8080",
"https": false,
"serviceRoot" :"com.XXXX.msalesoffline",
"streamParams" : "custom_header=Authorization:" + Autho + ";custom_header=X-SMP-APPCID:" + appcId + ";",
"definingRequests" : {
"ScopingDR" : "/ScopingCollection"
}
}
var store = sap.OData.createOfflineStore(properties);
store.open(
function success(){}
function error(){} );
Regards,
Suresh
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.