project BLF > class BCustomField > 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/bcustomfield.p)

define buffer bsCustomValue for t_sCustomValue.
define variable vcLookupReference as character case-sensitive no-undo.

<M-97 run StopExternalInstances  (output viFcReturnSuper (oiReturnStatus)) in BCustomField>

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

if oiReturnStatus < 0
then return.

empty temp-table tStoredSearchestoCreateCF.
empty temp-table tStoredSearchesToDeleteCF.

for each t_sCustomField where
         t_sCustomField.tc_Status <> "" on error undo, throw:
    if t_sCustomField.tc_Status <> "N"
    then do:
        find t_iCustomField where
             t_iCustomField.tc_Rowid = t_sCustomField.tc_Rowid
             no-error.

        if not available t_iCustomField
        then do:
            assign oiReturnStatus = -3.
            return.
        end.
    end.

    if (t_sCustomField.tcLookupType = ""  or
        t_sCustomField.tcLookupType = ?)  and
       (t_sCustomField.tc_Status    = "N" or
        t_sCustomField.tc_Status    = "C")
    then assign t_sCustomField.StoredSearch_ID = 0.

    if t_sCustomField.tcLookupType                   = {&LOOKUPTYPE-STOREDSEARCH}                   and
      (t_sCustomField.tc_Status                      = "N"                                          or
       t_sCustomField.tc_Status                      = "C"                                          and
      (t_sCustomField.tcLookupType                  <> t_iCustomField.tcLookupType                  or
       t_sCustomField.tcStoredSearchLookupReference <> t_iCustomField.tcStoredSearchLookupReference or
       t_sCustomField.tcStoredSearchName            <> t_iCustomField.tcStoredSearchName))
    then
    if t_sCustomField.tcStoredSearchLookupReference = ""
    or t_sCustomField.tcStoredSearchLookupReference = ?
    or t_sCustomField.tcStoredSearchName = ""
    or t_sCustomField.tcStoredSearchName = ?
    then do:
        <M-5 run SetMessage
           (input  #T-61'You must enter this field.':255(72)T-61# (icMessage), 
            input  '' (icArguments), 
            input  'tCustomField.tcStoredSearchName' (icFieldName), 
            input  t_sCustomField.tcStoredSearchName (icFieldValue), 
            input  'E' (icType), 
            input  3 (iiSeverity), 
            input  t_sCustomField.tc_Rowid (icRowid), 
            input  'blf-447021':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BCustomField>
        oiReturnStatus = -1.
    end.
    else do:
        <Q-7 run GetStoredSearch (all) (Read) (NoCache)
           (input t_sCustomField.tcStoredSearchLookupReference, (Reference)
            input ?, (CompanyId)
            input ?, (RoleID)
            input ?, (UserID)
            input t_sCustomField.tcStoredSearchName, (Name)
            output dataset tqGetStoredSearch) in BStoredSearch >

        find first tqGetStoredSearch where
                   tqGetStoredSearch.tcStoredSearchLookupRef = t_sCustomField.tcStoredSearchLookupReference and
                   tqGetStoredSearch.tcStoredSearchName      = t_sCustomField.tcStoredSearchName            and
                  (tqGetStoredSearch.tiUsr_ID                = 0                                            or
                   tqGetStoredSearch.tiUsr_ID                = ?)                                           and
                  (tqGetStoredSearch.tiRole_ID               = 0                                            or
                   tqGetStoredSearch.tiRole_ID               = ?)
                   no-error.

        if available tqGetStoredSearch
        then assign t_sCustomField.StoredSearch_ID = tqGetStoredSearch.tiStoredSearch_ID.
        else do:
            <M-63 run SetMessage
               (input  trim(#T-1'Stored search with name $1 and reference $2 does not exist.':100(6802)T-1#) (icMessage), 
                input  t_sCustomField.tcStoredSearchName + chr(2) + t_sCustomField.tcStoredSearchLookupReference (icArguments), 
                input  't_sCustomField.tcStoredSearchLookupReference' (icFieldName), 
                input  '' (icFieldValue), 
                input  'E' (icType), 
                input  3 (iiSeverity), 
                input  t_sCustomField.tc_Rowid (icRowid), 
                input  'BLF-443':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BCustomField>

            assign oiReturnStatus = -1.
        end.
    end.

    if t_sCustomField.tcLookupType                   = {&LOOKUPTYPE-BROWSE}        and
      (t_sCustomField.tc_Status                      = "N"                         or
       t_sCustomField.tc_Status                      = "C"                         and
      (t_sCustomField.tcLookupType                  <> t_iCustomField.tcLookupType or
       t_sCustomField.tcStoredSearchLookupReference <> t_iCustomField.tcStoredSearchLookupReference))
    then do:
        assign vcLookupReference = t_sCustomField.tcStoredSearchLookupReference.

        if vcLookupReference <> "QAD.Browse.MfgProLookupProvider"
        then do:
            <M-90 run SetMessage
               (input  trim(#T-2'For lookup type $1, the lookup reference has to be equal to $2 (case-sensitive!)':255(363890825)T-2#) (icMessage), 
                input  {&LOOKUPTYPE-BROWSE-TR} + chr(2) + 'QAD.Browse.MfgProLookupProvider' (icArguments), 
                input  't_sCustomField.tcStoredSearchLookupReference' (icFieldName), 
                input  t_sCustomField.tcStoredSearchLookupReference (icFieldValue), 
                input  'E' (icType), 
                input  3 (iiSeverity), 
                input  t_sCustomField.tc_Rowid (icRowid), 
                input  'BLF-444':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BCustomField>

            assign oiReturnStatus = -1.
        end.
    end.

    if t_sCustomField.tcLookupType                   = {&LOOKUPTYPE-GENCODE}       and
      (t_sCustomField.tc_Status                      = "N"                         or
       t_sCustomField.tc_Status                      = "C"                         and
      (t_sCustomField.tcLookupType                  <> t_iCustomField.tcLookupType or
       t_sCustomField.tcStoredSearchLookupReference <> t_iCustomField.tcStoredSearchLookupReference))
    then do:
        <M-36 run ValidateComponentGenCode
           (input  t_sCustomField.tc_Rowid (icRowid), 
            output viFcReturnSuper (oiReturnStatus)) in BCustomField>

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

    if t_sCustomField.tcLookupType                   = {&LOOKUPTYPE-OTHER}         and
      (t_sCustomField.tc_Status                      = "N"                         or
       t_sCustomField.tc_Status                      = "C"                         and
      (t_sCustomField.tcLookupType                  <> t_iCustomField.tcLookupType or
       t_sCustomField.tcStoredSearchLookupReference <> t_iCustomField.tcStoredSearchLookupReference))
    then do:
        if num-entries(t_sCustomField.tcStoredSearchLookupReference, ":") < 3 or
           num-entries(t_sCustomField.tcStoredSearchLookupReference, ":") > 4
        then do:
            <M-20 run SetMessage
               (input  trim(#T-3'For lookup type $1, the lookup reference must be constructed like this: $2.':255(169007754)T-3#) (icMessage), 
                input  {&LOOKUPTYPE-OTHER-TR} + chr(2) + chr(60) + 'LookupProvider Name' + chr(62) + ':' + chr(60) + 'Lookup Name' + chr(62) + ':' + chr(60) + 'ReturnField Name' + chr(62) + '[:' + chr(60) + 'FilterField Name' + chr(62) + ']' (icArguments), 
                input  't_sCustomField.tcStoredSearchLookupReference' (icFieldName), 
                input  t_sCustomField.tcStoredSearchLookupReference (icFieldValue), 
                input  'E' (icType), 
                input  3 (iiSeverity), 
                input  t_sCustomField.tc_Rowid (icRowid), 
                input  'BLF-442':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BCustomField>

            assign oiReturnStatus = -1.
        end.
    end.

    if oiReturnStatus                               >= 0                                            and
      (t_sCustomField.tcLookupType                   = {&LOOKUPTYPE-BROWSE}                         or
       t_sCustomField.tcLookupType                   = {&LOOKUPTYPE-GENCODE}                        or
       t_sCustomField.tcLookupType                   = {&LOOKUPTYPE-OTHER})                         and
      (t_sCustomField.tc_Status                      = "N"                                          or
       t_sCustomField.tc_Status                      = "C"                                          and
      (t_sCustomField.tcLookupType                  <> t_iCustomField.tcLookupType                  or
       t_sCustomField.tcStoredSearchLookupReference <> t_iCustomField.tcStoredSearchLookupReference or
       t_sCustomField.tcStoredSearchName            <> t_iCustomField.tcStoredSearchName))
    then do:
        if t_sCustomField.tcLookupType = {&LOOKUPTYPE-GENCODE}
        then assign t_sCustomField.tcStoredSearchName = {&LOOKUPTYPE-GENCODE}.
        else
        if t_sCustomField.tcLookupType = {&LOOKUPTYPE-OTHER}
        then assign t_sCustomField.tcStoredSearchName = entry(2, t_sCustomField.tcStoredSearchLookupReference, ":").

        if not can-find(first tStoredSearchesToCreateCF where
                              tStoredSearchesToCreateCF.tcStoredSearchLookupRef = t_sCustomField.tcStoredSearchLookupReference and
                              tStoredSearchesToCreateCF.tcStoredSearchName      = t_sCustomField.tcStoredSearchName)
        then do:
            create tStoredSearchesToCreateCF.

            assign tStoredSearchesToCreateCF.tcStoredSearchLookupRef = t_sCustomField.tcStoredSearchLookupReference
                   tStoredSearchesToCreateCF.tcStoredSearchName      = t_sCustomField.tcStoredSearchName
                   tStoredSearchesToCreateCF.tiStoredSearch_ID       = 0.
        end.

        assign t_sCustomField.StoredSearch_ID = 0.
    end.
end.

/* ================================================================= */
/* BLF-3636 custom value cannot be deleted when in use.              */
/* BLF-4273 unless all custom values are deleted.                    */
/* ================================================================= */
for each t_sCustomField where
         t_sCustomField.tc_Status <> "D" on error undo, throw:

if  t_sCustomField.tcLookupType <> {&LOOKUPTYPE-GENCODE}
and t_sCustomField.tcLookupType <> {&LOOKUPTYPE-OTHER}
and can-find (first t_sCustomValue where
                    t_sCustomValue.tc_ParentRowid = t_sCustomField.tc_Rowid and
                    t_sCustomValue.tc_Status <> "D")
then for each t_sCustomValue where
              t_sCustomValue.tc_ParentRowid = t_sCustomField.tc_Rowid and
             (t_sCustomValue.tc_Status = "D" or
              t_sCustomValue.tc_Status = "C") on error undo, throw:
    
    find t_iCustomValue where t_iCustomValue.tc_Rowid = t_sCustomValue.tc_Rowid no-error.
    if not available t_iCustomValue
    then next.
    
    if  t_sCustomValue.tc_Status = "C"
    and t_sCustomValue.CustomValueCode = t_iCustomValue.CustomValueCode
    then next.
    
    if can-find (first bsCustomValue where
                       bsCustomValue.tc_ParentRowid = t_sCustomField.tc_Rowid and
                       bsCustomValue.tc_Rowid <> t_sCustomValue.tc_Rowid and
                       bsCustomValue.CustomValueCode = t_iCustomValue.CustomValueCode)
    then next.
    
    <M-52 run BusinessFieldValueIsInUse
       (input  t_sCustomField.CustomFieldFieldName (icCustomFieldName), 
        input  t_iCustomValue.CustomValueCode (icCustomFieldValue), 
        output vlFcOk (olIsInUse), 
        output viFcReturnSuper (oiReturnStatus)) in BCustomField>
    if viFcReturnSuper <> 0
    then oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then return.
    if vlFcOk
    then do:
        oiReturnStatus = -1.
        <M-93 run SetMessage
           (input  #T-11'Unable to delete; custom value $1 is in use.':255(713132052)T-11# (icMessage), 
            input  t_iCustomValue.CustomValueCode (icArguments), 
            input  'tCustomValue.CustomValueCode' (icFieldName), 
            input  t_sCustomValue.CustomValueCode (icFieldValue), 
            input  'E' (icType), 
            input  3 (iiSeverity), 
            input  t_sCustomValue.tc_Rowid (icRowid), 
            input  'blf-260393':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BCustomField>
    end.
end.
end.

<ANCESTOR-CODE>