Versions Compared

Key

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

...

Then developers can modify the values after the SUPER:GetInitialValues call to implement the dynamic initial values. 

 

 

 

Step-by-step guide

 

Infocode
languagec#
titleCustomerBusinessEntity:GetInitialValues() method
    /**
     * Purpose: Returns a dataset with one record containing the initial values
     * Notes:
     * @param phDataset INPUT-OUTPUT DATASET-HANDLE
     * @param poParameter The GetInitialValuesParameter instance with the parameters for this call
     */
    METHOD PUBLIC OVERRIDE VOID GetInitialValues (INPUT-OUTPUT DATASET-HANDLE phDataset,
                                                  poParameter AS GetInitialValuesParameter):

        SUPER:GetInitialValues (INPUT-OUTPUT DATASET dsCustomer,
                                poParameter) .

        IF CAN-FIND (FIRST eCustomer) THEN DO:
            FIND FIRST eCustomer .

            /* Assign required initial values */
            ASSIGN eCustomer.Name        = "New customer":U
                   eCustomer.CreditLimit = 42 .

        END.

        FIND FIRST eCustomer NO-ERROR .

        ASSIGN phDataset = DATASET dsCustomer:HANDLE .

    END METHOD.

Step-by-step guide

To use the GetInitialValues method to initialize a new record in GUI for .NET, implement the following code in the DatasetController (e.g. CustomerDatasetController)

  1. Subscribe to the BeforeCreateRecord event of the SmartBusinessEntityAdapter or SmartDatasetChildAdapter from the common base class SmartDatasetAdapter

    Code Block
    languagec#
        METHOD PUBLIC VOID RegisterConsumer (poConsumer AS Progress.Lang.Object):
    
            IF TYPE-OF (poConsumer, SmartDatasetAdapter) THEN DO:
    
                CAST (poConsumer, SmartDatasetAdapter):BeforeCreateRecord:Subscribe (BeforeCreateRecordHandler) .
    
            END.
    
        END METHOD.
  2. In the event handler, invoke the GetInitialValues method of the CustomerBusinessEntity and BUFFER-COPY from the received template record into the new record.

    Code Block
    languagec#
        METHOD PRIVATE VOID BeforeCreateRecordHandler (sender AS System.Object,
                                                       e AS BeforeCreateRecordEventArgs):
    
            DEFINE VARIABLE oAdapter        AS SmartBusinessEntityAdapter NO-UNDO .
            DEFINE VARIABLE hDataset        AS HANDLE                     NO-UNDO .
            DEFINE VARIABLE hTemplateBuffer AS HANDLE                     NO-UNDO .
            DEFINE VARIABLE oParameter      AS GetInitialValuesParameter  NO-UNDO .
    
            oAdapter = SmartBusinessEntityAdapter:FromDatasetController(THIS-OBJECT) .
    
            oParameter = NEW GetInitialValuesParameter () .
            oParameter:TableNames = e:TableName .
    
            oAdapter:InvokeMethod ("GetInitialValues":U,
                                   INPUT-OUTPUT DATASET-HANDLE hDataset,
                                   oParameter) .
    
            hTemplateBuffer = hDataset:GET-BUFFER-HANDLE (e:TableName) .
    
            hTemplateBuffer:FIND-FIRST () .
    
            e:BufferHandle:BUFFER-COPY (hTemplateBuffer) .
    
            FINALLY:
                GarbageCollectorHelper:DeleteObject (hDataset) .
            END FINALLY.
    
        END METHOD.

To use the GetInitialValues method to initialize a new record in Angular (SmartComponents NG2), implement set the use-initial-values property of the smart-data-source components.

Filter by label (Content by label)
showLabelsfalse
max5
spacesSCLKB
showSpacefalse
sortmodified
reversetrue
typepage
cqllabel in ("smartdatasource","businessentity","smartbusinessentityadapter","initialvalue","smartviewercontrol") and type = "page" and space = "SCLKB"
labelsbusinessentity smartviewercontrol smartbusinessentityadapter initialvalue smartdatasource

...