Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

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).

Invokable methods need to provide a standardized signature:

The Business Entities dataset as an INPUT-OUTPUT parameter and a serializable object (Consultingwerk.ISerializable derived type). Note that the requirement that the parameter object (second parameter) implements the ISerializable interface is relaxed when the method only needs to be called from the AppServer.

Example of an invokable method
METHOD PUBLIC VOID PutCustomerOnHold (INPUT-OUTPUT DATASET dsCustomer, 
                                      poParameter AS Demo.PutOnHoldParameter):
    
    DEFINE VARIABLE oRequest AS FetchDataRequest NO-UNDO . 
    
    /* validation */
    ObjectAssert:IsValid (poParameter, "poParameter":U) .
    Assert:GreaterThanZero (poParameter:CustNum, "CustNum":U) .
    
    IF CharacterType:IsNullOrEmpty(poParameter:Comments) THEN 
        UNDO, THROW NEW Progress.Lang.AppError ("You must supply a comment to put a customer on hold.", 0) .
        
    /* fetch customer */
    oRequest = NEW FetchDataRequest ("eCustomer",
                                     SUBSTITUTE ("for each eCustomer where eCustomer.CustNum = &1",
                                                 poParameter:CustNum)) .
    THIS-OBJECT:FetchData (oRequest) . 
        
    FIND FIRST eCustomer . 
            
    /* Process data */
    THIS-OBJECT:TrackingChanges = TRUE . 
    
    ASSIGN eCustomer.Comments    = SUBSTITUTE ("Put on hold: &1~n&2", 
                                               STRING (NOW, "99.99.9999 hh:mm:ss":U),
                                               poParameter:Comments)  
           eCustomer.Terms       = "PREPAID ONLY":U
           eCustomer.Creditlimit = 0 .
            
    /* Save changes */                
    THIS-OBJECT:SaveChanges() .                
            
    DatasetHelper:ThrowDatasetErrors (DATASET dsCustomer:HANDLE) .                
            
END METHOD .

This example of an invokable method expects the PutCustomerOnHoldParameter class as a paramter. The dataset dsCustomer is not used for input. It's INPUT-OUTPUT definition is just to justify the requirement for an invokable method. In the first phase of the method, the input object and the properties of the object instance are validated. The second phase reads the customer with the given customer number. This is performed by calling into the Business Entities FetchData method. To process the data some fields of the temp-table record are updated and in the last phase those changes are saved using the SaveChanges method (leveraging all validation in the Business Entity or Data Access class).

 

 

  • No labels