project QadFinancials > class BMfgDomain > method PreSave

Description

Actions to take before writing current instance to the database (inside the db transaction!).
Use the field tc_status to test the status of the updated records:
'' = unchanged
'N' = new
'C' = changed
'D' = deleted


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program/bmfgdomain.p)

if not can-find(first tWriteCopyMfgDomain)
then do:

    <Q-6 run DomainsByDomainType (all) (Read) (NoCache)
       (input ?, (DomainID)
        input {&DOMAINSDOMAINTYPE-SYSTEM}, (DomainType)
        output dataset tqDomainsByDomainType) in BDomain >
        
    /* Now copy all the tables from the SYSTEM Domain to the new Domain */
    for first tqDomainsByDomainType where 
              tqDomainsByDomainType.tcDomainType = {&DOMAINSDOMAINTYPE-SYSTEM},
        each tdom_mstr where 
             tdom_mstr.dom_domain <> "":U  and 
             tdom_mstr.dom_domain <> tqDomainsByDomainType.tcDomainCode  and
             tdom_mstr.tc_Status   = 'N':U:
             
        <M-7 run AdditionalUpdatesCopyDomainCtrlTables
           (input  tqDomainsByDomainType.tcDomainCode (icSourceDomain), 
            input  tdom_mstr.dom_domain (icTargetDomain), 
            output viFcReturnSuper (oiReturnStatus)) in BMfgDomain>

        if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0  then return.
    end.

end.

/* If there are any to copy then start the persistence class and execute */
if can-find(first tWriteCopyMfgDomain)
then do: 
    <M-1 run StartPersistence (output vhFcComponent (ohPersistence), 
                           output viFcReturnSuper (oiReturnStatus)) in BMfgDomain>

    if viFcReturnSuper < 0 or
       oiReturnStatus  = 0
    then assign oiReturnStatus = viFcReturnSuper.

    if oiReturnStatus < 0
    then return.

    for each tWriteCopyMfgDomain:

        <M-2 run WriteCopy (input  tWriteCopyMfgDomain.tcWriteCopyTable (icTableName), 
                    input  tWriteCopyMfgDomain.tcWriteCopyPrepare (icPrepare), 
                    input  tWriteCopyMfgDomain.tcWriteCopyField (icFieldList), 
                    input  'c,i':U (icFieldListDataTypes), 
                    input  tWriteCopyMfgDomain.tcWriteCopyValue (icUpdateValue), 
                    input  {&TARGETPROCEDURE} (ihClass), 
                    input  vcUserLogin (icUserLogin), 
                    output viFcReturnSuper (oiReturnStatus)) in Progress>
       
        if viFcReturnSuper < 0 or
           oiReturnStatus  = 0
        then assign oiReturnStatus = viFcReturnSuper.

        /* -4 error is returned if no records can be found, but in our case these may not be set up for
           the SYSTEM domain, so we don't care about this error - MAYBE WE NEED WARNINGS???? */
        if viFcReturnSuper = -4 then 
            assign oiReturnStatus = 0.

    
        if oiReturnStatus < 0
        then 
            return.
    end.
end.

<ANCESTOR-CODE>