project BLF > class BDomain > method ValidateComponent

Description

Write here all tests on database update (new / modify / delete) that cannot be coded with a validation mask.
The type of update can be found in tc_status (N/C/D).
If you find incorrect data, you must write an entry in tFcMessages (using SetMessage) and set the return status of this method to either +1 or -1.
Return status +1 = data will still be accepted.
Return status -1 = data will not be accepted.
This method is run from SetPublicTables, before transferring the received data into the class temp-tables.


Parameters


oiReturnStatusoutputinteger


Internal usage


unused


program code (program/bdomain.p)

for each t_sDomains where
         t_sDomains.tc_Status = "N":U or
         t_sDomains.tc_Status = "C":U on error undo, throw:
    if t_sDomains.tc_Status = "C":U
    then do:
        find t_iDomains where
             t_iDomains.tc_Rowid = t_sDomains.tc_Rowid
             no-lock no-error.
        if not available t_iDomains
        then next. /* This validation is already automatically generated */
    end. /* if t_sDomains.tc_Status = "C":U */

    /* ============================================================================================= */
    /* The domain of the selected Primary Company should be the same as the domain you are updating. */
    /* ============================================================================================= */
    if t_sDomains.tcCompanyCode <> '':U  and
       t_sDomains.tcCompanyCode <> ?     and
      (t_sDomains.tc_Status      = "N":U or
       (t_sDomains.tc_Status      = "C":U and
        t_sDomains.tcCompanyCode <> t_iDomains.tcCompanyCode))
    then do:
        <Q-14 run CompanyByCompanyIdCode (all) (Read) (NoCache)
           (input 0, (CompanyId)
            input t_sDomains.tcCompanyCode, (CompanyCode)
            output dataset tqCompanyByCompanyIdCode) in BCompany >
        find tqCompanyByCompanyIdCode where

             tqCompanyByCompanyIdCode.tcCompanyCode = t_sDomains.tcCompanyCode
             no-lock no-error.
        if not available tqCompanyByCompanyIdCode
        then next. /* This validation is already automatically generated */

        if tqCompanyByCompanyIdCode.tiDomain_ID <> t_sDomains.Domain_ID
        then do:
            assign vcMessage      = trim(substitute(#T-15'The selected primary company (&1) is defined for another domain (&2).':100(8653)T-15#, trim(t_sDomains.tcCompanyCode), trim(tqCompanyByCompanyIdCode.tcDomainCode) ))
                   oiReturnStatus = -1.
            <M-16 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  't_sDomains.tcCompanyCode':U (icFieldName), 
                input  t_sDomains.tcCompanyCode (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  t_sDomains.tc_Rowid (icRowid), 
                input  'BLF-80':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BDomain>
        end. /* if tqCompanyByCompanyIdCode.tiDomain_ID <> t_sDomains.Domain_ID */
    end. /* if t_sDomains.tcCompanyCode <> '':U and ... */
end. /* for each t_sDomains where ... */

/* ================================ */
/* Actions for the DomainSharedSet  */
/* ================================ */
for each t_sDomainSharedSet where
         t_sDomainSharedSet.tc_status = "N":U or
         t_sDomainSharedSet.tc_status = "C":U
         on error undo, throw:
    /* SharedSetCode is mandatory */
    if t_sDomainSharedSet.tcSharedSetCode = "":U or
       t_sDomainSharedSet.tcSharedSetCode = ?    or
       t_sDomainSharedSet.tcSharedSetCode = "?":U
    then do:
        assign vcMessage      = trim(substitute(#T-1'You must enter the shared set code for &1':100(9099)T-1#, trim(t_sDomainSharedSet.tcSharedSetTypeTranslated) ))
               oiReturnStatus = -1.
        <M-5 run SetMessage (input  vcMessage (icMessage), 
                     input  '':U (icArguments), 
                     input  't_sDomainSharedSet.tcSharedSetCode':U (icFieldName), 
                     input  t_sDomainSharedSet.tcSharedSetCode (icFieldValue), 
                     input  'E':U (icType), 
                     input  3 (iiSeverity), 
                     input  t_sDomainSharedSet.tc_Rowid (icRowid), 
                     input  'BLF-77':U (icFcMsgNumber), 
                     input  '':U (icFcExplanation), 
                     input  '':U (icFcIdentification), 
                     input  '':U (icFcContext), 
                     output viFcReturnSuper (oiReturnStatus)) in BDomain>
    end.
    else do:
        /* check whether the entered code is valid */
         <Q-6 run SharedSetByIDCodeType (all) (Read) (NoCache)
            (input t_sDomainSharedSet.tcSharedSetCode, (SharedSetCode)
             input true, (SharedSetIsActive)
             input '':U, (SharedSetTypeCode)
             input ?, (SharedSetID)
             output dataset tqSharedSetByIDCodeType) in BSharedSet >
        find first tqSharedSetByIDCodeType no-error.
        if available tqSharedSetByIDCodeType
        then assign t_sDomainSharedSet.SharedSet_ID        = tqSharedSetByIDCodeType.tiSharedSet_ID
                    t_sDomainSharedSet.tcSharedSetTypeCode = tqSharedSetByIDCodeType.tcSharedSetTypeCode.
        else do:
            assign vcMessage      =  trim(substitute(#T-2'Invalid shared set code for &1.':100(9100)T-2#, trim(t_sDomainSharedSet.tcSharedSetTypeTranslated) ))
                   oiReturnStatus = -1.
            <M-7 run SetMessage (input  vcMessage (icMessage), 
                         input  '':U (icArguments), 
                         input  't_sDomainSharedSet.tcSharedSetCode':U (icFieldName), 
                         input  t_sDomainSharedSet.tcSharedSetCode (icFieldValue), 
                         input  'E':U (icType), 
                         input  3 (iiSeverity), 
                         input  t_sDomainSharedSet.tc_Rowid (icRowid), 
                         input  'BLF-78':U (icFcMsgNumber), 
                         input  '':U (icFcExplanation), 
                         input  '':U (icFcIdentification), 
                         input  '':U (icFcContext), 
                         output viFcReturnSuper (oiReturnStatus)) in BDomain>
        end.
    end.
end. /* for each t_sDomainSharedSet where */

/* ================================ */
/* Actions for the DomainType       */
/* ================================ */

/* Find out if a SYSTEM domain switch is allowed, validate if not... */
<I-9 {bFcOpenInstance
            &CLASS           = "Session"}>
<M-12 run GetLogicalValue (input  'AllowSystemDomainChange':U (icName), 
                           output vlAllowSystemDomainChange (olValue), 
                           output viFcReturnSuper (oiReturnStatus)) in Session>
<I-11 {bFcCloseInstance
            &CLASS           = "Session"}>
if vlAllowSystemDomainChange <> yes 
then do:

    for each t_sDomains on error undo, throw:
        
        assign vlSwitchingSystemDomain = no.
    
        if t_sDomains.tc_Status = "N":U 
        then assign vlSwitchingSystemDomain = t_sDomains.DomainType = {&DOMAINSDOMAINTYPE-SYSTEM}.
        
        /* If we're modifying the field then check whether changing to or from SYSTEM... */
        else if t_sDomains.tc_Status = "C":U 
             then do:
                 find t_iDomains where t_iDomains.tc_Rowid = t_sDomains.tc_Rowid no-error.
                 if not available t_iDomains
                 then next.
                 assign vlSwitchingSystemDomain = 
                          (t_sDomains.DomainType = {&DOMAINSDOMAINTYPE-SYSTEM} or 
                           t_iDomains.DomainType = {&DOMAINSDOMAINTYPE-SYSTEM})   and
                          t_iDomains.DomainType <> t_sDomains.DomainType.
             end.
        
        if vlSwitchingSystemDomain 
        then do:
            assign oiReturnStatus = -1
                   vcMessage      = trim(#T-8'The SYSTEM domain cannot be changed here.':80(6806)T-8#).
    
            <M-13 run SetMessage (input  vcMessage (icMessage), 
                      input  '' (icArguments), 
                      input  't_sDomains.DomainType':U (icFieldName), 
                      input  t_sDomains.DomainType (icFieldValue), 
                      input  'E':U (icType), 
                      input  3 (iiSeverity), 
                      input  t_sDomains.tc_Rowid (icRowid), 
                      input  'BLF-79':U (icFcMsgNumber), 
                      input  '' (icFcExplanation), 
                      input  '' (icFcIdentification), 
                      input  '' (icFcContext), 
                      output viFcReturnSuper (oiReturnStatus)) in BDomain>    
        end.
    end. /* for each t_sDomains */
end. /* if vlAllowSystemDomainChange <> yes */

/* ===================================================================================== */
/* Addtional Validation :                                                                */
/* In case DomainProperty.tcActCostPostingJournalCode is specified, then it will be used to state       */
/* DomainProperty.Journal_ID in BDomainProperty using the RKBF-mechanism. Within       */
/* this mechanism, the SharedSet that is used in combination with JournalCode to         */
/* state the Journal_ID is the SharedSet (of type JOURNAL) of the Domain where          */
/* the user is logged in.                                                                */
/* To state the correct Journal_ID, the SharedSet of the new Domain that is created     */
/* should be used instead of the SharedSet of the Domain where the user is logged in.   */
/* Solution:                                                                             */
/* The JournalCode may only be passed in case the Jrnl-SharedSet of the new Domain      */
/* that is created equals the Jrnl-SharedSet of the Domain where the user is logged in. */
/* ===================================================================================== */

/* Need to check whether to add this */

<ANCESTOR-CODE>