project QadFinancials > class BRoundingMethod > method ApiSynchronise

Description

ApiSynchronise: for creating initial rounding methods in the application. Method is executed doring system synchronize task.


Parameters


olUpdatesDoneoutputlogicalUpdates done?
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BSystem.ApiSynchroniseCustom2


program code (program9/broundingmethod.p)

assign oiReturnStatus      = -98
       viLocalReturnStatus = 0.
       
/* ClearData */
<M-1 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BRoundingMethod>
if viFcReturnSuper <> 0
then do: 
    assign oiReturnStatus = viFcReturnSuper.
    return.
end. /* if viFcReturnSuper <> 0 */    

/* Retrieve existing Rounding Methods */
<Q-2 run RoundingMethodPrim (all)  (Read)  (NoCache)  (input 0, (RoundingMethodID) 
                             input '':U, (RoundingMethodCode)
                             output dataset tqRoundingMethodPrim) in BRoundingMethod >

/* Create initial Rounding Methods */
find tqRoundingMethodPrim where
     tqRoundingMethodPrim.tcRoundingMethodCode = '0':U
     no-lock no-error.
if not available tqRoundingMethodPrim
then do:
    <M-5 run AddDetailLine (input  'RoundingMethod':U (icTable), 
                        input  '':U (icParentRowid), 
                        output viFcReturnSuper (oiReturnStatus)) in BRoundingMethod>    
    if viFcReturnSuper <> 0
    then do: 
        assign oiReturnStatus = viFcReturnSuper.
        return.
    end. /* if viFcReturnSuper <> 0 */
    
    assign tRoundingMethod.RoundingMethodCode        = '0':U
           tRoundingMethod.RoundingMethodDescription = trim(#T-4'Round to Ones':100(49008)T-4#)
           tRoundingMethod.RoundingMethodUnit        = 1
           tRoundingMethod.RoundingMethodThreshold   = 0.5.
end. /* find tqRoundingMethodPrim where RoundingMethodCode = '0':U */

find tqRoundingMethodPrim where
     tqRoundingMethodPrim.tcRoundingMethodCode = '1':U
     no-lock no-error.
if not available tqRoundingMethodPrim
then do:
    <M-6 run AddDetailLine (input  'RoundingMethod':U (icTable), 
                        input  '':U (icParentRowid), 
                        output viFcReturnSuper (oiReturnStatus)) in BRoundingMethod>    
    if viFcReturnSuper <> 0
    then do: 
        assign oiReturnStatus = viFcReturnSuper.
        return.
    end. /* if viFcReturnSuper <> 0 */
    
    assign tRoundingMethod.RoundingMethodCode        = '1':U
           tRoundingMethod.RoundingMethodDescription = trim(#T-7'Round to Tenths':100(49009)T-7#)
           tRoundingMethod.RoundingMethodUnit        = 0.1
           tRoundingMethod.RoundingMethodThreshold   = 0.05.
end. /* find tqRoundingMethodPrim where RoundingMethodCode = '0':U */

find tqRoundingMethodPrim where
     tqRoundingMethodPrim.tcRoundingMethodCode = '2':U
     no-lock no-error.
if not available tqRoundingMethodPrim
then do:
    <M-8 run AddDetailLine (input  'RoundingMethod':U (icTable), 
                        input  '':U (icParentRowid), 
                        output viFcReturnSuper (oiReturnStatus)) in BRoundingMethod>    
    if viFcReturnSuper <> 0
    then do: 
        assign oiReturnStatus = viFcReturnSuper.
        return.
    end. /* if viFcReturnSuper <> 0 */
    
    assign tRoundingMethod.RoundingMethodCode        = '2':U
           tRoundingMethod.RoundingMethodDescription = trim(#T-9'Round to Hundredths':100(49010)T-9#)
           tRoundingMethod.RoundingMethodUnit        = 0.01
           tRoundingMethod.RoundingMethodThreshold   = 0.005.
end. /* find tqRoundingMethodPrim where RoundingMethodCode = '0':U */

/* Validate Data */
<M-10 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BRoundingMethod>
if viFcReturnSuper <> 0 
then assign viLocalReturnStatus = viFcReturnSuper.
if viLocalReturnStatus < 0 
then do:
    assign oiReturnStatus = viLocalReturnStatus.
    return.
end.        

/* Additional Updates */
<M-11 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BRoundingMethod>
if viFcReturnSuper <> 0 
then assign viLocalReturnStatus = viFcReturnSuper.
if viLocalReturnStatus < 0 
then do:
    assign oiReturnStatus = viLocalReturnStatus.
    return.
end.        

/* DataSave */
<M-12 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BRoundingMethod>
if viFcReturnSuper <> 0 
then assign viLocalReturnStatus = viFcReturnSuper.
if viLocalReturnStatus < 0 
then do:
    assign oiReturnStatus = viLocalReturnStatus.
    return.
end.        
                                            
assign oiReturnStatus = viLocalReturnStatus
       olUpdatesDone  = true.


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 = "BRoundingMethod".
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.