project QadFinancials > class BMfgProject > method ApiReplicateFromFinancials

Description

Replicate Project to MFG Project


Parameters


tCopyProjectinputtemp-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 BProject.ApiReplicateFromDaemon


program code (program9/bmfgproject.p)

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

/* ================== */
/* Exception Handling */
/* ================== */
assign oiReturnStatus                  = -98
       viLocalReturnStatus             = 0
       vlQueryStartedDomainBySharedSet = false
       vlQueryStartedTranslation       = false
       vcListPjMstr                    = '':U.

CONVERTBLOCK:
DO:
    /* ===================================== */
    /* Check which records need to be loaded */
    /* ===================================== */
    for each tCopyProject
        break by tCopyProject.SharedSet_ID:
    
        /* =============== */
        /* Start the query */
        /* =============== */
        if vlQueryStartedDomainBySharedSet = false
        then do:
            <Q-1 run DomainBySharedSetDomain  (Start) in BDomain >
            assign vlQueryStartedDomainBySharedSet = true.
        end. /* if vlQueryStartedDomainBySharedSet = false */
    
        /* ============================================================================================== */
        /* Check if the Project 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(tCopyProject.SharedSet_ID)
        then do:
            <Q-2 run DomainBySharedSetDomain (all) (Read) (Cache)
               (input tCopyProject.SharedSet_ID, (SharedSetId)
                input 0, (DomainID)
                input icDomainCode, (DomainCode)
                output dataset tqDomainBySharedSetDomain) in BDomain >
        end. /* if first-of(tCopyProject.SharedSet_ID) */
            
        for each tqDomainBySharedSetDomain where
                 tqDomainBySharedSetDomain.tlDomainPropertyIsSetupCompl:
            /* ============================================================ */
            /* Create a list of all tpj_mstr records that need to be loaded */
            /* ============================================================ */
            <Q-19 assign vlFcQueryRecordsAvailable = PjMstrByProjectDomain (NoCache)
               (input tCopyProject.ProjectCode, (Project)
                input tqDomainBySharedSetDomain.tcDomainCode, (Domain)) in BMfgProject >
            if vlFcQueryRecordsAvailable = true
            then assign vcListPjMstr = vcListPjMstr                           + 
                                       (if vcListPjMstr = '':U
                                        then '':U
                                        else chr(4))                          +
                                       tqDomainBySharedSetDomain.tcDomainCode +
                                       chr(2)                                 +
                                       tCopyProject.ProjectCode.
        end. /* for each tqDomainBySharedSetDomain: */
    end. /* for each tCopyProject */
    
    /* ========================= */
    /* Load the tpj_mstr records */
    /* ========================= */
    if vcListPjMstr <> "":U and 
       vcListPjMstr <> ?
    then do :
        <M-4 run DataLoad
           (input  '':U (icRowids), 
            input  vcListPjMstr (icPkeys), 
            input  '':U (icObjectIds), 
            input  '':U (icFreeform), 
            input  false (ilKeepPrevious), 
            output viFcReturnSuper (oiReturnStatus)) in BMfgProject>
        if viFcReturnSuper <> 0
        then do:
            assign viLocalReturnStatus = viFcReturnSuper.
            leave CONVERTBLOCK.
        end. /* if viFcReturnSuper <> 0 */
    end. /* if vcListPjMstr <> "":U and */
    /* =================================== */
    /* Convert table tGL to table tpj_mstr */
    /* =================================== */
    for each tCopyProject
        break by tCopyProject.SharedSet_ID:
    
        /* =============== */
        /* Start the query */
        /* =============== */
        if vlQueryStartedDomainBySharedSet = false
        then do:
            <Q-5 run DomainBySharedSetDomain  (Start) in BDomain >
            assign vlQueryStartedDomainBySharedSet = true.
        end. /* if vlQueryStartedDomainBySharedSet = false */
    
        /* ============================================================================================== */
        /* Check if the Project 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(tCopyProject.SharedSet_ID)
        then do:
            if tCopyProject.SharedSet_ID = 0 or
               tCopyProject.SharedSet_ID = ?
            then do:
                assign vcMessage           = trim(substitute(#T-15'The shared set ID for project (&1) was not defined.':255(69588)t-15#, trim(tCopyProject.ProjectCode) ))
                       viLocalReturnStatus = -3.
                <M-6 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-8174':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BMfgProject>
                leave CONVERTBLOCK.
            end. /* if tCopyProject.SharedSet_ID = 0 or */

            <Q-7 run DomainBySharedSetDomain (all) (Read) (Cache)
               (input tCopyProject.SharedSet_ID, (SharedSetId)
                input 0, (DomainID)
                input icDomainCode, (DomainCode)
                output dataset tqDomainBySharedSetDomain) in BDomain >            
        end. /* if first-of(tCopyProject.SharedSet_ID) */
            
        for each tqDomainBySharedSetDomain where
                 tqDomainBySharedSetDomain.tlDomainPropertyIsSetupCompl:
            /* ======================================================= */
            /* Create or update tpj_mstr records based on tCopyProject */
            /* ======================================================= */
            find tpj_mstr where
                 tpj_mstr.pj_project = tCopyProject.ProjectCode and
                 tpj_mstr.pj_domain  = tqDomainBySharedSetDomain.tcDomainCode
                 no-error.
            if not available tpj_mstr
            then do:
                if tCopyProject.tc_Status = "D"
                then next.

                <M-8 run AddDetailLine
                   (input  'pj_mstr':U (icTable), 
                    input  '':U (icParentRowid), 
                    output viFcReturnSuper (oiReturnStatus)) in BMfgProject>
                if viFcReturnSuper <> 0
                then do:
                    assign viLocalReturnStatus = viFcReturnSuper.
                    leave CONVERTBLOCK.
                end. /* if viFcReturnSuper <> 0 */                

                assign tpj_mstr.oid_pj_mstr = <M-9 GetNextOidValue  () in BMfgProject> no-error.
                if error-status:error
                then do:
                    assign vcMessage           = trim(#T-16'The system cannot retrieve an OID value while replicating projects.':255(69589)t-16#) + chr(10) +
                                                 trim(substitute(#T-17'Project: &1.':255(708)T-17#, trim(tCopyProject.ProjectCode)))
                           viLocalReturnStatus = -1.
                    if ERROR-STATUS:NUM-MESSAGES > 0
                    then assign vcMessage = vcMessage + chr(10) + 
                                            trim(substitute(#T-18'Detailed info: &1 (&2).':255(466)T-18#,ERROR-STATUS:GET-MESSAGE(1),string(ERROR-STATUS:GET-NUMBER(1)))).
                    <M-10 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-8175':U (icFcMsgNumber), 
                        input  '':U (icFcExplanation), 
                        input  '':U (icFcIdentification), 
                        input  '':U (icFcContext), 
                        output viFcReturnSuper (oiReturnStatus)) in BMfgProject>
                    leave CONVERTBLOCK.
                end.
            end. /* if not available tpj_mstr */  
            else assign tpj_mstr.tc_Status = "C":U.

            
            assign tpj_mstr.pj_domain    = tqDomainBySharedSetDomain.tcDomainCode
                   tpj_mstr.pj_project   = tCopyProject.ProjectCode
                   tpj_mstr.pj_desc      = tCopyProject.ProjectDescription
                   tpj_mstr.pj_findate   = tCopyProject.ProjectOriginalCompletDate
                   tpj_mstr.pj_revfin    = tCopyProject.ProjectRevisedCompletDate
                   tpj_mstr.pj_revdate   = tCopyProject.ProjectDateRevised
                   tpj_mstr.pj_beg_dt    = tCopyProject.ProjectStartDate
                   tpj_mstr.pj_active    = (if tCopyProject.ProjectSystemStatus = {&PROJECTSYSTEMSTATUS-OPEN}
                                            then true
                                            else false)
                   tpj_mstr.pj_comp      = (if tCopyProject.ProjectSystemStatus = {&PROJECTSYSTEMSTATUS-OPEN}
                                            then ?
                                            else if tCopyProject.ProjectSystemStatus = {&PROJECTSYSTEMSTATUS-INITIAL}
                                                 then tpj_mstr.pj_comp
                                                 else today)
                   tpj_mstr.tc_Status    = (if tCopyProject.tc_Status = "D":U
                                            then tCopyProject.tc_Status
                                            else tpj_mstr.tc_Status).            

            if vlQueryStartedTranslation = false
            then do:
                <Q-20 run TranslationByIDLngParent  (Start) in BTranslation >                  
                assign vlQueryStartedTranslation = true.
            end.

            <Q-21 run TranslationByIDLngParent (all) (Read) (NoCache)
               (input tqDomainBySharedSetDomain.tiLng_ID, (LngID)
                input tCopyProject.Project_ID, (ParentID)
                input 0, (TranslationID)
                output dataset tqTranslationByIDLngParent) in BTranslation >            
            find first tqTranslationByIDLngParent no-error.
            if available tqTranslationByIDLngParent 
            then assign tpj_mstr.pj_desc = tqTranslationByIDLngParent.tcTranslationStringText.
        end. /* for each tqDomainBySharedSetDomain: */
    end. /* for each tCopyProject */
end. /* CONVERTBLOCK */

/* ============== */
/* Stop the query */
/* ============== */
if vlQueryStartedDomainBySharedSet = true
then do:
    <Q-11 run DomainBySharedSetDomain  (Stop) in BDomain >
    assign vlQueryStartedDomainBySharedSet = false.
end. /* if vlQueryStartedDomainBySharedSet = true */

if vlQueryStartedTranslation = true
then do:
    <Q-22 run TranslationByIDLngParent  (Stop) in BTranslation >                  
    assign vlQueryStartedTranslation = false.
end.

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

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

    /* ================== */
    /* Additional Updates */
    /* ================== */
    <M-13 run AdditionalUpdates  (output viFcReturnSuper (oiReturnStatus)) in BMfgProject>
    if viFcReturnSuper <> 0
    then assign viLocalReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then leave VALIDATEBLOCK.
    
    /* ======== */
    /* DataSave */
    /* ======== */
    <M-14 run DataSave  (output viFcReturnSuper (oiReturnStatus)) in BMfgProject>
    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 = "BMfgProject".
create ttContext.
assign ttContext.propertyName = "methodName"
       ttContext.propertyValue = "ApiReplicateFromFinancials".
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/bmfgproject.apireplicatefromfinancials.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icDomainCode = <parameter value>.

vhParameter = vhInputDS:get-buffer-handle("tCopyProject").
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.