project QadFinancials > class BGLType > method ApiSynchronise

Description

ApiSynchronise; this method will do the synchronisation (=upload of the gl-types).


Parameters


olUpdatesDoneoutputlogicalUpdatesDone
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BSystem.ApiSynchroniseCustom


program code (program9/bgltype.p)

/* ================== */
    /* Clear the instance */
    /* ================== */
    <M-2 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BGLType>
    if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
    if oiReturnStatus < 0 then return.
    
    /* ========================= */
    /* Load all existing GLTypes */
    /* ========================= */
    <M-9 run DataLoad
          (input  '':U (icRowids), 
           input  '':U (icPkeys), 
           input  '':U (icObjectIds), 
           input  '' (icFreeform), 
           input  false (ilKeepPrevious), 
           output viFcReturnSuper (oiReturnStatus)) in BGLType>
    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 (untranslatable and translatable) values. */
    /* Here we will only use the even-entries because we just need the untranlatable values          */
    /* ============================================================================================= */
    assign vcGlTypeCode = {&GLTYPECODES}.

    assign viMaxCounter = num-entries(vcGlTypeCode,chr(2)). 
    do viCounter = viMaxCounter to 2 by -2 :
        find tGLType where 
             tGLType.GLTypeCode = entry(viCounter,vcGlTypeCode,chr(2))
             no-lock no-error.

        if not available tGLType
        then do :
            <M-5 run AddDetailLine (input  'GLTYPE':U (icTable), 
                        input  '':U (icParentRowid), 
                        output viFcReturnSuper (oiReturnStatus)) in BGLType>
            if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
            if oiReturnStatus < 0 then return.
            assign tGLType.GLTypeCode       = entry(viCounter,vcGlTypeCode,chr(2))
                   tGLType.GLTypeIsActive   = true
                   olUpdatesDone            = true.
        end. /* if not available tGLType */
        else if tGLType.GLTypeIsActive = false
             then assign tGLType.GLTypeIsActive   = true
                         tGLType.tc_Status        = "C":U
                         olUpdatesDone            = true.
    end. /* do viCounter */
        
    /* ======================================================================== */
    /* De-acttivate all existing GL-type that are no longer in the preprocessor */
    /* ======================================================================== */
    for each tGLType where
             tGLType.GLTypeIsActive = true :
        assign vlTypeIsStillValid = false.
        do viCounter = viMaxCounter to 1 by -2 :
            if tGLType.GLTypeCode = entry(viCounter,vcGlTypeCode,chr(2))
            then do :
                assign vlTypeIsStillValid = true.
                Leave.
            end. /* if tGLType.GLTypeCode = entry(viCounter,vcGlTypeCode,chr(2)) */
        end. /* do viCounter */
        if vlTypeIsStillValid = false
        then assign tGLType.GLTypeIsActive   = false
                    tGLType.tc_Status        = "C":U
                    olUpdatesDone            = true.
    end. /* for each tGLType */
    
    /* ==================================== */
    /* Validate, AdditionalUpdates and Save */
    /* ==================================== */
    <M-6 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BGLType>
    if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
    if oiReturnStatus < 0 then return.
    <M-7 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BGLType>
    if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
    if oiReturnStatus < 0 then return.
    <M-8 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BGLType>
    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 = "BGLType".
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.