project QadFinancials > class BMfgAddressListDetail > method ApiReplicateFromFinancialsEndUser

Description

Replicate Debtor End User to MFG/PRO Address List Detail


Parameters


tDebtorEndusersToUpdate2inputtemp-table
icDomainCodeinputcharacterWhen the domaincode is filled --> Replicate only to this domain.
If the domaincode is empty --> Replicate to all domains in this shared set.
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BMfgEndUser.AdditionalUpdates


program code (program9/bmfgaddresslistdetail.p)

/* ====================== */
/* Check input parameters */
/* ====================== */
if not can-find(first tDebtorEndUsersToUpdate2)
then return.

/* ================== */
/* Exception Handling */
/* ================== */
assign oiReturnStatus                  = -98
       viLocalReturnStatus             = 0
       vcListLsMstr                    = '':U.

CONVERTBLOCK:
DO:
    /* ===================================== */
    /* Check which records need to be loaded */
    /* ===================================== */
    for each tDebtorEndUsersToUpdate2
        break by tDebtorEndUsersToUpdate2.SharedSet_ID:
    
        /* ============================================================================================== */
        /* Check if the Account needs to be replicated to one domain or to all domains of this shared set */
        /* If icDomainCode is left blank, all domains for this shared set will be replicated.             */
        /* ============================================================================================== */
        if first-of(tDebtorEndUsersToUpdate2.SharedSet_ID)
        then do:
            <Q-23 run DomainBySharedSetDomain (all) (Read) (Cache)
               (input tDebtorEndUsersToUpdate2.SharedSet_ID, (SharedSetId)
                input 0, (DomainID)
                input icDomainCode, (DomainCode)
                output dataset tqDomainBySharedSetDomain) in BDomain >
        end. /* if first-of(tDebtorEndUsersToUpdate2.SharedSet_ID) */
        
        /* =============================================================================================== */
        /* Get all Mfg Addresses which are already defined in the database                                 */
        /* =============================================================================================== */
        <Q-41 run DomainSharedSetForLsMstr (all) (Read) (NoCache)
           (input tDebtorEndUsersToUpdate2.SharedSet_ID, (SharedSetId)
            input icDomainCode, (DomainCode)
            input tDebtorEndusersToUpdate2.DebtorEndUserCode, (Address)
            input {&ADDRESSTYPECODESYSTEM-ENDUSER}, (AddressType)
            output dataset tqDomainSharedSetForLsMstr) in BDomain >
            
        for each tqDomainBySharedSetDomain where
                 tqDomainBySharedSetDomain.tlDomainPropertyIsSetupCompl:
            /* ============================================================ */
            /* Create a list of all tls_mstr records that need to be loaded */
            /* ============================================================ */
            if can-find(first tqDomainSharedSetForLsMstr where
                              tqDomainSharedSetForLsMstr.tcDomainCode = tqDomainBySharedSetDomain.tcDomainCode     and
                              tqDomainSharedSetForLsMstr.tcls_addr    = tDebtorEndusersToUpdate2.DebtorEndUserCode and
                              tqDomainSharedSetForLsMstr.tcls_type    = {&ADDRESSTYPECODESYSTEM-ENDUSER})
            then assign vcListLsMstr = vcListLsMstr                             + 
                                       (if vcListLsMstr = '':U
                                        then '':U
                                        else chr(4))                            +
                                       tqDomainBySharedSetDomain.tcDomainCode   +
                                       chr(2)                                   +
                                       tDebtorEndUsersToUpdate2.DebtorEndUserCode +
                                       chr(2)                                   +
                                       {&ADDRESSTYPECODESYSTEM-ENDUSER}.
            if length(vcListLsMstr, "CHARACTER") > 30000
            then do:
                
                /* ========================= */
                /* Load the tls_mstr records */
                /* ========================= */
                <M-3 run DataLoad
                   (input  '':U (icRowids), 
                    input  vcListLsMstr (icPkeys), 
                    input  '':U (icObjectIds), 
                    input  '':U (icFreeform), 
                    input  true (ilKeepPrevious), 
                    output viFcReturnSuper (oiReturnStatus)) in BMfgAddressListDetail>
                                        
                if viFcReturnSuper <> 0
                then assign viLocalReturnStatus = viFcReturnSuper.

                assign vcListLsMstr = '':U.   
            end. /* length */
        end. /* for each tqDomainBySharedSetDomain: */
    end. /* for each tDebtorEndUsersToUpdate2 */
    
    /* ========================= */
    /* Load the tls_mstr records */
    /* ========================= */
    if vcListLsMstr <> "":U and 
       vcListLsMstr <> ?
    then do :
        <M-24 run DataLoad
           (input  '':U (icRowids), 
            input  vcListLsMstr (icPkeys), 
            input  '':U (icObjectIds), 
            input  '':U (icFreeform), 
            input  false (ilKeepPrevious), 
            output viFcReturnSuper (oiReturnStatus)) in BMfgAddressListDetail>
        if viFcReturnSuper <> 0
        then do:
            assign viLocalReturnStatus = viFcReturnSuper.
            leave CONVERTBLOCK.
        end. /* if viFcReturnSuper <> 0 */
    end. /*if vcListLsMstr <> "":U and */

    /* ======================================================= */
    /* Convert table tDebtorEndUsersToUpdate2 to table tls_mstr */
    /* ======================================================= */
    for each tDebtorEndUsersToUpdate2
        break by tDebtorEndUsersToUpdate2.SharedSet_ID:
    
        /* ============================================================================================== */
        /* Check if the EndUser needs to be replicated to one domain or to all domains of this shared set  */
        /* If icDomainCode is left blank, all domains for this shared set will be replicated.             */
        /* ============================================================================================== */
        if first-of(tDebtorEndUsersToUpdate2.SharedSet_ID)
        then do:
            if tDebtorEndUsersToUpdate2.SharedSet_ID = 0 or
               tDebtorEndUsersToUpdate2.SharedSet_ID = ?
            then do:
                assign vcMessage           = trim(substitute(#T-36'The shared set ID for customer end user (&1) was not defined.':255(69664)t-36#, trim(string(tDebtorEndUsersToUpdate2.DebtorEndUserCode)) ))
                       viLocalReturnStatus = -3.
                <M-26 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'E':U (icType), 
                    input  1 (iiSeverity), 
                    input  '':U (icRowid), 
                    input  'QadFin-8242':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BMfgAddressListDetail>
                leave CONVERTBLOCK.
            end. /* if tDebtorEndUsersToUpdate2.SharedSet_ID = 0 or */

            <Q-27 run DomainBySharedSetDomain (all) (Read) (Cache)
               (input tDebtorEndUsersToUpdate2.SharedSet_ID, (SharedSetId)
                input 0, (DomainID)
                input icDomainCode, (DomainCode)
                output dataset tqDomainBySharedSetDomain) in BDomain >            
        end. /* if first-of(tDebtorEndUsersToUpdate2.SharedSet_ID) */
            
        for each tqDomainBySharedSetDomain where
                 tqDomainBySharedSetDomain.tlDomainPropertyIsSetupCompl:
            /* ================================================================== */
            /* Create or update tls_mstr records based on tDebtorEndUsersToUpdate2 */
            /* ================================================================== */
            find tls_mstr where
                 tls_mstr.ls_addr   = tDebtorEndUsersToUpdate2.DebtorEndUserCode and
                 tls_mstr.ls_domain = tqDomainBySharedSetDomain.tcDomainCode   and
                 tls_mstr.ls_type   = {&ADDRESSTYPECODESYSTEM-ENDUSER}
                 no-error.
            if not available tls_mstr
            then do:
                if tDebtorEndUsersToUpdate2.tc_Status = "D"
                then next.

                <M-28 run AddDetailLine
                   (input  'ls_mstr':U (icTable), 
                    input  '':U (icParentRowid), 
                    output viFcReturnSuper (oiReturnStatus)) in BMfgAddressListDetail>
                if viFcReturnSuper <> 0
                then do:
                    assign viLocalReturnStatus = viFcReturnSuper.
                    leave CONVERTBLOCK.
                end. /* if viFcReturnSuper <> 0 */                
                
            end. /* if not available tls_mstr */  
            else assign tls_mstr.tc_Status = "C":U.

            assign tls_mstr.ls_addr       = tDebtorEndUsersToUpdate2.DebtorEndUserCode
                   tls_mstr.ls_domain     = tqDomainBySharedSetDomain.tcDomainCode
                   tls_mstr.ls_type       = {&ADDRESSTYPECODESYSTEM-ENDUSER}
                   tls_mstr.tc_Status     = (if tDebtorEndUsersToUpdate2.tc_Status = "D":U
                                             then tDebtorEndUsersToUpdate2.tc_Status
                                             else tls_mstr.tc_Status).
        end. /* for each tqDomainBySharedSetDomain: */
    end. /* for each tDebtorEndUsersToUpdate2 */
end. /* CONVERTBLOCK */

VALIDATEBLOCK:
DO:
    if viLocalReturnStatus < 0
    then leave VALIDATEBLOCK.

    /* ========== */
    /* ValidateBC */
    /* ========== */
    <M-33 run ValidateBC  (output viFcReturnSuper (oiReturnStatus)) in BMfgAddressListDetail>
    if viFcReturnSuper <> 0
    then assign viLocalReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then leave VALIDATEBLOCK.

    /* ================== */
    /* Additional Updates */
    /* ================== */
    <M-34 run AdditionalUpdates  (output viFcReturnSuper (oiReturnStatus)) in BMfgAddressListDetail>
    if viFcReturnSuper <> 0
    then assign viLocalReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then leave VALIDATEBLOCK.
    
    /* ======== */
    /* DataSave */
    /* ======== */
    <M-35 run DataSave  (output viFcReturnSuper (oiReturnStatus)) in BMfgAddressListDetail>
    if viFcReturnSuper <> 0
    then assign viLocalReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then leave VALIDATEBLOCK.
end. /* VALIDATEBLOCK */

/* ================== */                        
/* Exception Handling */
/* ================== */
assign oiReturnStatus = viLocalReturnStatus.


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 = "BMfgAddressListDetail".
create ttContext.
assign ttContext.propertyName = "methodName"
       ttContext.propertyValue = "ApiReplicateFromFinancialsEndUser".
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 = "".

/* Create input dataset */
create dataset vhInputDS.
vhInputDS:read-xmlschema("file", "xml/bmfgaddresslistdetail.apireplicatefromfinancialsenduser.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icDomainCode = <parameter value>.

vhParameter = vhInputDS:get-buffer-handle("tDebtorEndusersToUpdate2").
vhParameter:buffer-create().
assign vhParameter::<field-name-1> = <field-value-1>
       vhParameter::<field-name-2> = <field-value-2>
       ...

/* 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.