Client JavaScript code: An Invoke
- Last Updated: June 26, 2019
- 3 minute read
- OpenEdge
- Version 13.0
- Documentation
The following JavaScript illustrates an asynchronous call to the preceding
method using an afterInvoke event callback
(onAfterInvokeGetCreditInfo) to handle the results:
|
This sample code:
- Subscribes an event-handler callback,
onAfterInvokeGetCreditInfo, to theafterInvokeevent to enable error-checking and processing of the results. - Defines the object variable,
currentCust, to specify the value of thepiCustNuminput parameter passed toGetCreditInfo( ). - Calls
GetCreditInfo( )on thedsCustomerJSDO asynchronously. - The callback function tests for the success of the Invoke operation and
accesses both the operation return value (
_retVal) and its one output parameter (poCustomer) to do the normal thing for a successful execution, and accesses any returned errors for an unsuccessful execution. - In the assignment of
request.poCustomer.poCustomerto thepoCustomervariable, the parameter name (poCustomer) must be specified twice. The first instance refers to the parameter name as defined in the ABL routine; the second instance is the name of the JavaScript object containing the table data that the server serializes as JSON to send to the client.
The following JavaScript illustrates an asynchronous call to the same method using Promise callbacks to handle the results:
|
This sample code:
- Defines the object variable,
currentCust, to specify the value of thepiCustNuminput parameter passed toGetCreditInfo( ). - Calls
GetCreditInfo( )on thedsCustomerJSDO asynchronously using the JSDOinvoke( )API to return a Promise object. - Chains access to the
done( )method on the returned Promise object to register a callback function that handles successful operation execution. This callback accesses both the Invoke operation return value (_retVal) and its one output parameter (poCustomer) to do the normal thing for a successful execution. - Chains access to the
fail( )method on the returned Promise object to register a callback function that handles unsuccessful operation execution. This callback accesses and handles any returned errors. - In the assignment of
request.poCustomer.poCustomerto thepoCustomervariable, the parameter name (poCustomer) must be specified twice. The first instance refers to the parameter name as defined in the ABL routine; the second instance is the name of the JavaScript object containing the table data that the server serializes as JSON to send to the client.
The following JavaScript illustrates a synchronous call to the same method:
|
This sample code:
- Defines two object variables:
currentCustto specify the value of thepiCustNuminput parameter passed toGetCreditInfo( ), andrequestto hold the request object reference returned as the value ofGetCreditInfo( ). - Uses
try...catchblocks to handle certain errors. - Calls
GetCreditInfo( )on thedsCustomerJSDO to test the contents of its returned request object, and either do the normal thing for a successful execution or throw various error strings for an unsuccessful Invoke operation or other errors encountered. - Might not be a good example of an Invoke operation for synchronous
execution, because it is not executed to return a value within an expression, and in
addition to a return value it also returns an output parameter (
poCustomer) containing the corresponding Customer record with a small subset of fields. Searching a large result set for the specified record to return in this output parameter can block for an extended period of time.