How to call a function in Openedge on oepas from Kendo javas

Posted by richyoder555 on 13-Feb-2018 07:44

I have an application that lists orders in a stacked datagrid.  Currently I have a button one each line that triggers a fetch of a PDF file from the static folder with the file name derived from the order number (Thanks to ).

The PDFs need to be current an so are generated (by the server) when the orders are fetched. This can be slow for the end user as there can be many orders.

What I would like to do is somehow call (openedge) code on the server with the order number that is selected.  This in turn, would generate a single PDF and send it to the client.

Posted by egarcia on 13-Feb-2018 13:36

You are welcome.

The error message "Uncaught TypeError: this[name] is not a function" is seen when name for the invoke operation is not found in the catalog file.

You can confirm this by looking at your catalog.json file to check whether the invoke operation named GeneratePdf is listed there.

Please notice that after adding an invoke operation to a Business Entity, you would need to go through the Edit ABL Service wizard to re-generate the catalog. (Defined Services/Edit)

I hope this helps.

All Replies

Posted by Peter Judge on 13-Feb-2018 08:00

The standard way is to create a method that does this, and add it to your catalog an an ”invoke” operation. The Kendo side is then responsible for calling that operation and consuming the results.

Posted by egarcia on 13-Feb-2018 08:47

Hello,

> What I would like to do is somehow call (openedge) code on the server with the order number that is selected.

> This in turn, would generate a single PDF and send it to the client.

Here is a link that describes the usage of invoke operations with the JSDO:

community.progress.com/.../2938.calling-invoke-operations-with-the-jsdo

From a Kendo UI Builder app, you would either create a new JSDO instance for the resource or use the JSDO instance associated with the Kendo UI DataSource in your view.

The syntax to use access the DataSource depends on the view type.

Here is how it would look from a custom view in a new function in controller.public.js:

Here OrderOrderLineDS is the DataSource defined for the view.

  getMonthlySales(piYear, pcSalesRep) {
        var that = this;
        // var jsdo = new progress.data.JSDO({ name: "OrderOrderLine" });
        var jsdo = this.$ds.OrderOrderLineDS.transport.jsdo;

        piYear = Math.trunc(piYear);
        jsdo.invoke("MonthlySales", { piYear: piYear, pcSalesRep: pcSalesRep })
            .then(function (jsdo, success, request) {
                console.log("Success: ", request.response.ttSales.ttSales);
                angular.element("#textbox0").val("");
                request.response.ttSales.ttSales.forEach(function (element) {
                    console.log(
                        "SalesRep: " + element.SalesRep
                        + " Month: " + element.Month
                        + " " + "Sales: " + element.Sales);

                    if (element.Month === 1) {
                        angular.element("#textbox0").val(element.Sales);
                    }
                });
            }, function () {
                console.log("Error while calling invoke operation.");
            });
    }

From a built-in view, the access to the DataSource would look like the following:

var jsdo = this.$ds[this.$primeDSName].transport.jsdo;

You can check controller.js to see how the DataSource is defined.

The invoke method in the Business Entity would look like the following:

    @openapi.openedge.export(type="REST", useReturnValue="false", writeDataSetBeforeImage="false").
    @progress.service.resourceMapping(type="REST", operation="invoke", URI="/MonthlySales", alias="", mediaType="application/json").
    METHOD PUBLIC VOID MonthlySales(
        INPUT piYear AS INTEGER,
        INPUT pcSalesRep AS CHARACTER,
        OUTPUT TABLE ttSales ):

...
    END METHOD.

In your particular case, you might need to encode the PDF into a LONGCHAR so that it can be transferred via the parameters. If you are using a temp-table, please notice that the access to the values, as shown in function getMonthlySales(), would have the name of the temp-table (ttSales) twice, once to represent the name of the parameter and a 2nd time to represent the value of the temp-table structure.

I hope this helps.

It contains a method with the following structure:
 
    @openapi.openedge.export(type="REST", useReturnValue="false", writeDataSetBeforeImage="false").
    @progress.service.resourceMapping(type="REST", operation="invoke", URI="/MonthlySales", alias="", mediaType="application/json").
    METHOD PUBLIC VOID MonthlySales(
        INPUT piYear AS INTEGER,
        INPUT pcSalesRep AS CHARACTER,
        OUTPUT TABLE ttSales ):
...
    END METHOD.

Posted by richyoder555 on 13-Feb-2018 12:58

Thank you for the example, this helps a lot.  I think I understand all of this but somehow I still am not doing this right.

I'm getting this error in the console: Uncaught TypeError: this[name] is not a function

Here is the javascript I am trying to use:

GeneratePdf(piOrder) {

 console.log('GeneratePdf');

 var jsdo = this.$ds[this.$primeDSName].transport.jsdo;

     jsdo.invoke("GeneratePdf", { piOrder: piOrder})

         .then(function (jsdo, success, request) {

 console.log("pdf success");

         }, function () {

             console.log("Error while calling invoke operation.");

         });

 }

and on the BusinessClass side:

   @openapi.openedge.export(type="REST", useReturnValue="false", writeDataSetBeforeImage="false").

   @progress.service.resourceMapping(type="REST", operation="invoke", URI="/GeneratePdf", alias="", mediaType="application/json").

   METHOD PUBLIC VOID GeneratePdf(

       INPUT piOrder AS INTEGER):

   ...

   END METHOD.  

Posted by egarcia on 13-Feb-2018 13:36

You are welcome.

The error message "Uncaught TypeError: this[name] is not a function" is seen when name for the invoke operation is not found in the catalog file.

You can confirm this by looking at your catalog.json file to check whether the invoke operation named GeneratePdf is listed there.

Please notice that after adding an invoke operation to a Business Entity, you would need to go through the Edit ABL Service wizard to re-generate the catalog. (Defined Services/Edit)

I hope this helps.

Posted by richyoder555 on 13-Feb-2018 15:10

Please notice that after adding an invoke operation to a Business Entity, you would need to go through the Edit ABL Service wizard to re-generate the catalog. (Defined Services/Edit)

That's what I was missing.  Thank you!

This thread is closed