Extending jsdo/ABL API - Invoke?

Posted by Mike McMillan on 19-Jul-2017 13:19

I think I need to use "invoke".

Is there any documentation/examples on how to call your ABL code utilizing the jsdo framework?

The requirement is simple but I cannot find anything to help me with the task.

I need to call a .p or .cls the will take 2 jsdo/dataset input/output parameters.

I would like to see a basic "Hello World" example of both the javascript and the ABL

All Replies

Posted by egarcia on 19-Jul-2017 17:02

Hello Mike,

You can call an invoke method in two ways by name or using the invoke() method.

Calling the invoke method by name looks like the following:

   jsdo_orderOrderLine.MonthlySales(params);

This approach is used in the following sample:

   oemobiledemo.progress.com/.../example016.html

You can use the Web Inspector in your web browser to review the code.

In this case, you would subscribe to the AfterInvoke event to process the response.

Using the invoke() method would look like the following:

   var promise = jsdo_orderOrderLine.invoke('MonthlySales', params);

In this case, you would use the promise object that is returned to process the response of the request.

See the following article in the documentation:

documentation.progress.com/.../index.html

The parameter to the invoke method is an object with properties for each of the parameters that you are sending to the server.

Here is the code from the example mentioned above:

                               jsdo_orderOrderLine.MonthlySales({

                                   pcSalesRep: salesRep,

                                   piYear: 2014

                               });  

Internally, the JSDO wraps these parameters in a request object.

See the following link for related info:

community.progress.com/.../17303

The declaration of the method in the ABL side looks 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 ):

The key when sending a dataset to the server using an invoke operation, that the value of the parameter that corresponds to the dataset needs to be the JSON object representing the actual dataset. This means that if you look at the JSON sent to the server, you would see the name of the dataset twice. (This also applies to a temp-table.)

jsdo.invoke("MyMethod", {

       "myDataSet": {

           "myDataSet": {

               "table": [{

                   "field1": "value1",

                   "field2": "value2"

               }]

           }

       }

   })

The 1st "myDataSet" is the name of the parameter. The 2nd myDataSet is listed because it is part of the dataset structure.

Please the following thread which has information on this subject:

community.progress.com/.../83883

Please let me know if you need additional information.

I hope this helps,

Edsel

This thread is closed