Calling the web service in Mobile App

1. Create Source Code:

Ext.define("Terrasoft.configuration.service.UsrYourService", {
    alternateClassName: "Terrasoft.UsrYourService",
    statics: {
 
        serviceUrl: "rest/UsrYourService/",  // Name of your Service
 
        yourAction: function(config) {
            var data = {
                recordId: config.id // Input parameter(s) of service
            };
            Terrasoft.RequestManager.issueRequest({
                supressRequestEvents: false,
                requestFn: Terrasoft.Ajax.request,
                requestFnConfig: {
                    url: Terrasoft.util.encodeServiceUrl(this.serviceUrl) + config.action,
                    method: "POST",
                    jsonData: data,
                    success: function(response) {
                        var decodedResponse = Ext.JSON.decode(response.responseText, true);
                        Ext.callback(config.success, config.scope, [decodedResponse]);
                    },
                    failure: function(response) {
                        var parser = Ext.create("Terrasoft.ServiceResponseParser", response);
                        var exception = parser.getServiceFailureException();
                        Ext.callback(config.failure, config.scope, [exception]);
                    },
                    scope: this
                },
                responseToStatusCodeFn: function(response) {
                    return response.status;
                },
                scope: Terrasoft.Ajax
            });
        }
    }
});

2. Add in MobileApplicationManifest your service into CustomSchemas block:

"CustomSchemas": [
    "UsrYourService"
]

3. Call service from your code:

yourFunction: function() {
    Terrasoft.UsrYourService.yourAction({
        id: this.record.getId(), // RecordId
        action: "Start", // Method of service
        success: this.serviceSuccess, // Success callback
        failure: this.serviceFailure, // Error callback
        scope: this
    });
},
serviceSuccess: function(response) {
    if (response.isSuccess) {
        ///TODO: do something
    } else {
        Terrasoft.MessageBox.showMessage(Terrasoft.LocalizableStrings.StartErrorMessage); // Error message
    }
},
serviceFailure: function(error) {
    var response = error.getResponse();
    Terrasoft.MessageBox.showMessage(response.statusText);
}

 

Like 0

Like

Share

0 comments
Show all comments