Calling Invoke Operations with the JSDO - Wiki - Mobile - Progress Community

Calling Invoke Operations with the JSDO

Calling Invoke Operations with the JSDO

Description

Methods in a Business Entities exposed as invoke operations can be called from a JSDO instance by using the invoke() method:

Syntax:

invoke ( op-name [ , input-object ] ) : jQuery Promise 

jsdo.invoke( op-name, input-object).then( success-handler, error-handler );

The response of an invoke operation can be processed using the success and error handlers for the Promise.

Note: The response can also be handled by using the AfterInvoke event.

The input-object is a JavaScript object where the properties correspond to the input parameters of the method.

Example:

{

param1: <value param1>

param2: <value param2>

...

}

The key point here is that when the parameters correspond to a dataset or a temp-table, the value uses the structure of a dataset or a temp-table. This means that you would see name of the dataset and temp-table twice. Once as the name of the parameter as a second time as part of the value in the structure of the dataset or the temp-table.

The response of the invoke operation is handled by processing the request.response property passed as parameters to the success and error handlers. The request.response object contains properties corresponding to the output parameters. For dataset and temp-table parameters you would also observe the name of the dataset and temp-table twice.

Please notice how the "ttSales" name is listed twice in the response payload and also how it used in the sample program.

The datasets and temp-tables used in an invoke operation can use same schema as the one one for the resource as well as other schema definitions.

Sample Program

<!DOCTYPE html>
<html>
<head>
    <script src="http://cdn.kendostatic.com/2015.1.429/js/jquery.min.js"></script>
    <script src="http://oemobiledemo.progress.com/jsdo/progress.jsdo.js"></script>
</head>
<body>
<script>
/*global progress */
var serviceURI = "http://oemobiledemo.progress.com/OEMobileDemoServices"; 
var catalogURI = "http://oemobiledemo.progress.com/OEMobileDemoServices/static/SportsService.json";

progress.data.getSession({
    serviceURI: serviceURI,
    catalogURI: catalogURI,
    authenticationModel: "anonymous"
}).done(function () {
    var jsdo = new progress.data.JSDO({ name: 'OrderOrderLine' });

    jsdo.invoke("MonthlySales", {piYear: 1998, pcSalesRep: "BBB"})
        .then(function (jsdo, success, request) {
            console.log("Success: ", request.response.ttSales.ttSales);
            request.response.ttSales.ttSales.forEach(function (element) {
                console.log(
                    "SalesRep: " + element.SalesRep 
                    + " Month: " + element.Month 
                    + " " + "Sales: " + element.Sales);
            });
        }, function () {
            console.log("Error while calling invoke operation.");
        });
}).fail(function () {
    console.log("Error while creating session.");
});
</script>
</body>
</html>

Resources

Comments
  • Trying this code as is, got this:

    Access to XMLHttpRequest at 'oemobiledemo.progress.com/.../home.html from origin 'null' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.