project QadFinancials > class BAddressType > method ApiSynchronise

Description

System Procedure ApiSynchronise to synchronise the Address-type database-records.


Parameters


olUpdatesDoneoutputlogicalThis output parameter will return true if a db-update was done within the method.
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BSystem.ApiSynchroniseCustom


program code (program9/baddresstype.p)

/* ================== */
    /* Clear the instance */
    /* ================== */
    <M-13 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BAddressType>
    if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
    if oiReturnStatus < 0 then return.
    
    /* ========================= */
    /* Load all existing GLTypes */
    /* ========================= */
    <M-14 run DataLoad
          (input  '':U (icRowids), 
           input  '':U (icPkeys), 
           input  '':U (icObjectIds), 
           input  '' (icFreeform), 
           input  false (ilKeepPrevious), 
           output viFcReturnSuper (oiReturnStatus)) in BAddressType>
    if viFcReturnSuper = -4 /* nothing-read - emtpy-table */
    then assign viFcReturnSuper = 0.
    if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
    if oiReturnStatus < 0 then return.
    
    /* ==================================================================================================== */
    /* Go through the preprocessor containing all possible (no translatable values for AddressType) values. */
    /* ==================================================================================================== */
    assign vcAddressTypeCodeSystems = {&ADDRESSTYPECODESYSTEMS}
           viMaxCounter             = num-entries(vcAddressTypeCodeSystems,chr(2)). 
    do viCounter = viMaxCounter to 1 by -1 :
        find tAddressType where 
             tAddressType.AddressTypeCode = entry(viCounter,vcAddressTypeCodeSystems,chr(2))
             no-lock no-error.
        if not available tAddressType
        then do :
            <M-15 run AddDetailLine (input  'ADDRESSTYPE':U (icTable), 
                         input  '':U (icParentRowid), 
                         output viFcReturnSuper (oiReturnStatus)) in BAddressType>
            if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
            if oiReturnStatus < 0 then return.
            assign tAddressType.AddressTypeCode            = entry(viCounter,vcAddressTypeCodeSystems,chr(2))
                   tAddressType.AddressTypeIsActive        = true
                   tAddressType.AddressTypeIsSystemDefined = true
                   tAddressType.AddressTypeDescription     = trim(substitute(#T-19'Description for: &1':40(171)T-19#, string(tAddressType.AddressTypeCode)))
                   olUpdatesDone                           = true.
        end. /* if not available tAddressType */
        else if tAddressType.AddressTypeIsActive = false
             then assign tAddressType.AddressTypeIsActive        = true
                         tAddressType.AddressTypeIsSystemDefined = true
                         tAddressType.tc_Status                  = "C":U
                         olUpdatesDone                           = true.
    end. /* do viCounter */
        
    /* ============================================================================================= */
    /* De-acttivate all existing System-defined Address-types that are no longer in the preprocessor */
    /* ============================================================================================= */
    for each tAddressType where
             tAddressType.AddressTypeIsSystemDefined = true and
             tAddressType.AddressTypeIsActive        = true :
        assign vlTypeIsStillValid = false.
        do viCounter = viMaxCounter to 1 by -1 :
            if tAddressType.AddressTypeCode = entry(viCounter,vcAddressTypeCodeSystems,chr(2))
            then do :
                assign vlTypeIsStillValid = true.
                Leave.
            end. /* if tAddressType.AddressTypeCode = entry(viCounter,vcAddressTypeCodeSystems,chr(2)) */
        end. /* do viCounter */
        if vlTypeIsStillValid = false
        then assign tAddressType.AddressTypeIsActive   = false
                    tAddressType.tc_Status             = "C":U
                    olUpdatesDone                      = true.
    end. /* for each tGLType */
    
    /* ==================================== */
    /* Validate, AdditionalUpdates and Save */
    /* ==================================== */
    <M-16 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BAddressType>
    if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
    if oiReturnStatus < 0 then return.
    <M-17 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BAddressType>
    if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
    if oiReturnStatus < 0 then return.
    <M-18 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BAddressType>
    if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
    if oiReturnStatus < 0 then return.


Sample code: how to call this method through RPCRequestService (QXtend Inbound)

define temp-table ttContext no-undo
    field propertyQualifier as character
    field propertyName as character
    field propertyValue as character
    index entityContext is primary unique
        propertyQualifier
        propertyName
    index propertyQualifier
        propertyQualifier.

define dataset dsContext for ttContext.

define variable vhContextDS as handle no-undo.
define variable vhExceptionDS as handle no-undo.
define variable vhServer as handle no-undo.
define variable vhInputDS as handle no-undo.
define variable vhInputOutputDS as handle no-undo.
define variable vhOutputDS as handle no-undo.
define variable vhParameter as handle no-undo.

/* Create context */
create ttContext.
assign ttContext.propertyName = "programName"
       ttContext.propertyValue = "BAddressType".
create ttContext.
assign ttContext.propertyName = "methodName"
       ttContext.propertyValue = "ApiSynchronise".
create ttContext.
assign ttContext.propertyName = "applicationId"
       ttContext.propertyValue = "fin".
create ttContext.
assign ttContext.propertyName = "entity"
       ttContext.propertyValue = "1000".
create ttContext.
assign ttContext.propertyName = "userName"
       ttContext.propertyValue = "mfg".
create ttContext.
assign ttContext.propertyName = "password"
       ttContext.propertyValue = "".

/* Connect the AppServer */
create server vhServer.
vhServer:connect("-URL <appserver-url>").

if not vhServer:connected()
then do:
    message "Could not connect AppServer" view-as alert-box error title "Error".
    return.
end.

/* Run */
assign vhContextDS = dataset dsContext:handle.

run program/rpcrequestservice.p on vhServer
    (input-output dataset-handle vhContextDS by-reference,
           output dataset-handle vhExceptionDS,
     input        dataset-handle vhInputDS by-reference,
     input-output dataset-handle vhInputOutputDS by-reference,
           output dataset-handle vhOutputDS).

/* Handle output however you want, in this example, we dump it to xml */
if valid-handle(vhExceptionDS)
then vhExceptionDS:write-xml("file", "Exceptions.xml", true).

if valid-handle(vhOutputDS)
then vhOutputDS:write-xml("file", "Output.xml", true).

/* Cleanup */
vhServer:disconnect().
assign vhServer = ?.

if valid-handle(vhInputDS)
then delete object vhInputDS.

if valid-handle(vhOutputDS)
then delete object vhOutputDS.

if valid-handle(vhExceptionDS)
then delete object vhExceptionDS.