Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Invokable methods in Business Entities provide a very efficient way to implement reusable business logic in a Business Entity. Invokable methods are accessible both through the Service Interface (on the AppServer or from other business logic) or through the Service Adapter (from the GUI client).

...

Code Block
titleSample of invoking the method through the Service Adapter (client)
linenumberstrue
{Demo/Customer/dsCustomer.i}

DEFINE VARIABLE oParameter AS PutOnHoldParameter NO-UNDO . 

oParameter = NEW PutOnHoldParameter (42, "We need to talk to this customer") .


FrameworkSettings:ServiceAdapter:InvokeMethod ("":U,                                     /* default partition */
                                               "Demo.Customer.CustomerBusinessEntity":U, /* Business Entity name */
                                               "PutCustomerOnHold":U,                    /* method name */
                                               INPUT-OUTPUT DATASET dsCustomer,
                                               oParameter) .

...

Code Block
titleSample of invoking the method through the Service Interface (business logic)
linenumberstrue
{Demo/Customer/dsCustomer.i}


DEFINE VARIABLE oParameter AS PutOnHoldParameter NO-UNDO . 


oParameter = NEW PutOnHoldParameter (42, "We need to talk to this customer") .


ServiceInterface:InvokeMethod ("Demo.Customer.CustomerBusinessEntity":U, /* Business Entity name */
                               "PutCustomerOnHold":U,                    /* method name */
                               INPUT-OUTPUT DATASET dsCustomer,
                               oParameter) .

Creating a proxy method in the DatasetModel class 

DatasetModel classes provide a highly efficient way of interacting with a Business Entity from custom code. By default they provide simple access to the read and update functionality of the business entity.

The Business Entity Designer (the ModelClassGeneratorPlugin) can create proxy methods for invokable methods in the business entity when "regenerating" the Business Entity source code from the Business Entity Designer. This functionality relies on an annotation outside of the invokable method:

Code Block
titleAnnotation sample
linenumberstrue
@InvokeMethod (template="invoke-receive-dataset") . 
/*------------------------------------------------------------------------------
    Purpose: Puts the Customer on hold 
    Notes:   Client callable method
    @param dsCustomer INPUT-OUTPUT DATASET
    @param poParameter The Parameter Object for this method 
------------------------------------------------------------------------------*/
METHOD PUBLIC VOID PutCustomerOnHold (INPUT-OUTPUT DATASET dsCustomer, 
                                      poParameter AS Demo.PutOnHoldParameter):

The @InvokeMethod annotation is required and the template parameter defines a template for the proxy method to be used when regenerating the dataset model class:

Code Block
titleSample of the PutCustomerOnHold method in the CustomerDatasetModel_Generated class
linenumberstrue
/*------------------------------------------------------------------------------
    Purpose: Invokes the Business Entity Method PutCustomerOnHold  
    Notes:   Receives the dataset PutCustomerOnHold from the backend
    @param poParameter The Parameter Object for this method 
------------------------------------------------------------------------------*/
METHOD PUBLIC VOID PutCustomerOnHold (poParameter AS Demo.PutOnHoldParameter):
        
    DATASET dsCustomer:EMPTY-DATASET () .
        
    IF THIS-OBJECT:UseInterface = Consultingwerk.OERA.UseInterfaceEnum:ServiceAdapter THEN 
        Consultingwerk.Framework.FrameworkSettings:ServiceAdapter:InvokeMethod ("":U,
                                                                                THIS-OBJECT:EntityName,
                                                                                "PutCustomerOnHold":U,
                                                                                INPUT-OUTPUT DATASET dsCustomer,
                                                                                poParameter) .
    ELSE 
        Consultingwerk.OERA.ServiceInterface:InvokeMethod (THIS-OBJECT:EntityName,
                                                           "PutCustomerOnHold":U,
                                                           INPUT-OUTPUT DATASET dsCustomer,
                                                           poParameter) .
    {Consultingwerk/foreachABL.i Consultingwerk.OERA.TableModel oTable in THIS-OBJECT:TableModels}
        IF VALID-HANDLE (oTable:QueryHandle) THEN DO:
            oTable:QueryHandle:QUERY-OPEN () .
            oTable:QueryHandle:GET-FIRST () .

 

 

 

 

...


        END. 
    END.
        
END METHOD .

Invoking the method through the DatasetModel class instance

Code Block
titleSample of invoking the method though the DatasetModel instance
linenumberstrue
oCustomer = NEW CustomerDatasetModel () .
oCustomer:PutCustomerOnHold (NEW PutOnHoldParameter (7, "Urgent!")) .
BufferHelper:ShowBuffer (oCustomer:DatasetHandle::eCustomer) .

Templates for proxy methods

The "template" parameter to the @InvokeMethod defines which code template should be used when creating the template method.

The default template name (when the template parameter is missing) is: "invoke-receive-dataset". Templates are expected to be located in the "DatasetModelInvokeMethods" sub folder of the Business Entity Designer template folder (e.g. Consultingwerk\BusinessEntityDesigner\Generator\Templates).

The following templates are provided by Consultingwerk:

Template nameDescription
invoke-receive-dataset (default)

Invokes the method in the Business Entity. Does not pass the current dataset contents from the DatasetModel instance to the method.

The dataset is emptied before calling. When the method returns, the data which was returned from the Business Entity method replaces the data in the DatasetModel instance so that the updated/new data is available in the dataset model instance.

invoke-no-dataset

Invokes the method in the Business Entity. Does not pass the current dataset contents from the DatasetModel instance to the method.

When the method returns, the data which was returned from the Business Entity method is not stored. The data in the DatasetModel instance keep unchanged when calling the Business Entity method.

Customers can create custom method templates if needed.