invoke( ) method
- Last Updated: June 20, 2019
- 5 minute read
- OpenEdge
- Version 13.0
- Documentation
Asynchronously calls a custom invocation method on the JSDO to execute an Invoke operation defined by a Data Object resource.
OpenEdge resources can define and implement custom invocation methods that you can call using this method.
The asynchronous execution of the specified invocation method using
invoke( ) returns results using a jQuery Promise. You can also
directly call an invocation method on the JSDO either synchronously, returning results as
its return value, or asynchronously, returning results using a callback subscribed to the
afterInvoke event.
invoke( ) successfully, jQuery
Promises must be supported in your development environment. Otherwise, the method throws an
exception.For more information on the possible implementations for custom invocation methods, and how to call them directly on the JSDO, see the description of the invocation method.
addRecords( ) method
to merge any record data that is returned by an invocation method into JSDO memory.Return type: jQuery Promise
Applies to: progress.data.JSDO class
Syntax
|
- op-name
- A
stringthat specifies the name of the invocation method as defined by the resource. - input-object
- An object whose properties and values match the case-sensitive names
and data types of the input parameters specified for the server routine that implements
the invocation method. If the implementing routine does not take input parameters,
specify
nullor leave out the argument entirely.
Promise method callback signatures
jQuery Promise objects define methods that register a callback function
with a specific signature. The callback signatures depend on the method that returns the
Promise. Following are the signatures of callbacks registered by methods in any Promise
object that invoke( ) returns:
Syntax:
|
- promise
- A reference to the Promise object that is returned as the value of
the
invoke( )method. For more information on Promises, see the notes on Promises in the description of the progress.data.JSDO class. - jsdo
- A reference to the JSDO that invoked the
invoke( )method (Invoke operation) on its resource. For more information, see the description of the jsdo property of the request object. - success
- A
booleanthat istrueif the Invoke operation was successful. For more information, see the description of the success property of the request object.Note: It is not always necessary to test the value of success in a Promise method callback for theinvoke( )method, especially if the callback is registered usingpromise.done( )andpromise.fail( ), where the callback executes according to this value. - request
- A reference to the request object returned after the
invoke( )method completed execution and returned any results from its Invoke operation on the server. For more information, see the description of the request object.
Returning and handling results
This method returns results asynchronously in two different ways, and in the following order, depending on the development environment used to build the mobile app:
- Using JSDO named events for all environments —
The following events fire before and after the
invoke( )method executes, respectively, with results handled by callback functions that you subscribe as documented for each event: - Using a Promise object returned for environments
that support jQuery Promises — Any callbacks that you register using Promise object
methods all execute both after the
invoke( )method itself and after any subscribedafterInvokeevent callbacks for the op-name-specified invocation method complete execution. Note that the signatures of all Promise method callbacks match the signature of theafterInvokeevent callback function so you can specify an existingafterInvokeevent callback as the callback function that you register using any Promise method.
Because the callbacks that you register with any returned Promise methods
execute only after all subscribed afterInvoke event
callbacks for the op-name-specified invocation method
complete execution, you can invoke logic in the Promise method callbacks to modify any
processing done by the event callbacks.
If the invoke( ) method completes
successfully, the success parameter for any afterInvoke event callback or Promise method and the success property of each handler's request parameter object are both set to true. Otherwise, both the success parameter
and success property are set to false, and you can read any error results by inspecting the setting of the
response property in the same request parameter object.
The request object returned as an input parameter to any subscribed event callback or to any registered Promise object callback contains several properties depending on the status of the Invoke operation.
For a successful execution, if there are any output parameters or a method
return value, they are returned as properties of an object referenced by the response property of the request object. For an OpenEdge
resource, the referenced properties for output parameters match the case-sensitive names and
data types of the output parameters defined for the implementing ABL routine. Any method
return value is returned by a JSDO-defined _retVal
property with a matching JavaScript data type. For information on data type mappings for an
OpenEdge resource, see OpenEdge ABL to JavaScript data type mappings.
For an unsuccessful execution in an OpenEdge resource, the request object
response property references an object that can contain
a both a _retVal property, which is a string value with the error information, and an _errors property, which is an array with information on one or
more errors. For more information on error information returned in the response property,
see the description of the response property.
For more information on working with the results of invocation methods that you call with
invoke( ), see the notes on handling results in the description of the
invocation method.
Example
The following code fragment shows invoke( ) calling an
invocation method (getOrderTotalAndStatus( )) as defined
for an OpenEdge resource (dsCustomerOrder), with
asynchronous results returned in appropriate callbacks registered by methods of the returned
Promise object:
|
Note that for the call to getOrderTotalAndStatus( ) in the previous example, its input parameters are
passed in paramObject, as required by the implementing ABL routine.
Depending on the success of the getOrderTotalAndStatus( )
call, the appropriate callback registered for the Promise executes, making it unnecessary to
test its success parameter.
Thus, when the callback registered by the Promise's
done( ) method executes for a successful getOrderTotalAndStatus( ) call, the order total is returned as the method return
value in the JSDO-defined _retVal property, and the one output parameter
with the order status is returned as the value of the ABL-defined pcStatus
property, both of which are returned in the response property object. When
the callback registered by the Promise's fail( ) method executes for an
unsuccessful getOrderTotalAndStatus( ) call, the callback
inspects the response property to return one or more
possible error messages in an array of objects.
See also:
addRecords( ) method, fill( ) method, invocation method, record property, request object, saveChanges( ) method