project BLF > class Business Component > method GetCustomFieldValues

Description

fill in a column of a temp-table with custom fields from a business object main table


Parameters


ihResultSetBufferinputhandle(buffer) handle to the temp-table that must be updated
icClassinputcharactershortname of the business class from which custom fields must be read
icTableinputcharacterdatabase table name from which custom fields must be read
icKeyColumninputcharactername of the column in the result set temp-table that contains the value of primary key of the objects for which custom fields must be read
icCustomFieldColumninputcharactername of the column in the result set temp-table where custom field values will be stored
icCustomBusinessFieldinputcharacterThe can be left blank.
You can specify here the name of the custom busininess fields if you want the value of just 1 of them.
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


BLF
method breport.GetSelectedCustomFields

QadFinancials
method BBudgetReporting.BudgetOverview


program code (program1/business.p)

if oiReturnStatus = 0
then oiReturnStatus = -98.

if ihResultSetBuffer:type <> "BUFFER":U
then do:
    <M-13 run SetMessage (input  'Invalid buffer handle ($1)':U (icMessage), 
                      input  program-name(1) (icArguments), 
                      input  '' (icFieldName), 
                      input  '' (icFieldValue), 
                      input  'S':U (icType), 
                      input  3 (iiSeverity), 
                      input  '' (icRowid), 
                      input  'BLF-259':U (icFcMsgNumber), 
                      input  '' (icFcExplanation), 
                      input  '' (icFcIdentification), 
                      input  '' (icFcContext), 
                      output viFcReturnSuper (oiReturnStatus)) in business>
    assign oiReturnStatus = -3.
    return.
end.

assign vhCustom = ihResultSetBuffer:buffer-field (icCustomFieldColumn) no-error.
if vhCustom <> ?
then do:
    viKeyCount = num-entries(icKeyColumn).
    do viFcCount1 = 1 to viKeyCount:
        vhKey[viFcCount1] = ihResultSetBuffer:buffer-field (entry(viFcCount1,icKeyColumn)) no-error.
        if vhKey[viFcCount1] = ?
        then do:
            viKeyCount = 0.
            leave.
        end.
    end.
end.

if viKeyCount = 0
then do:
    <M-14 run SetMessage (input  'Invalid column name ($1)':U (icMessage), 
                      input  program-name(1) (icArguments), 
                      input  '' (icFieldName), 
                      input  '' (icFieldValue), 
                      input  'S':U (icType), 
                      input  3 (iiSeverity), 
                      input  '' (icRowid), 
                      input  'BLF-260':U (icFcMsgNumber), 
                      input  '' (icFcExplanation), 
                      input  '' (icFcIdentification), 
                      input  '' (icFcContext), 
                      output viFcReturnSuper (oiReturnStatus)) in business>
    assign oiReturnStatus = -3.
    return.
end.

/* ================================================================= */
/* Retrieve field name of active custom fields.                      */
/* ================================================================= */
<M-15 run CustomFields (input  icTable (icTableName), 
                        output vcFieldNames (ocFieldNames), 
                        output vcFieldLabels (ocFieldLabels), 
                        output viFcReturnSuper (oiReturnStatus)) in business>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.

if vcFieldNames = ""
then do:
    if oiReturnStatus = -98
    then oiReturnStatus = 0.
    return.
end.

assign vlUseSingleItem = false.

if icCustomBusinessField <> ? and icCustomBusinessField <> ''
then do viFcCount1 = 1 to num-entries(vcFieldNames):
    if entry(viFcCount1,vcFieldNames) = icCustomBusinessField
    then do:
         assign vcFieldNames = icCustomBusinessField
                vlUseSingleItem = true.
         leave.
    end.
end.

/* ================================================================= */
/* Retrieve field name of primary index fields.                      */
/* ================================================================= */
<M-16 run BusinessClassActions
   (input  icClass (icClassShortname), 
    input  'START+OPEN':U (icAction), 
    input  no (ilSubtransaction), 
    input-output viOpenC (biClassOpenCount), 
    input-output vhBC (bhClassInstanceHandle), 
    input-output viBC (biClassInstanceId), 
    input  '' (icDraftReference), 
    output viFcReturnSuper (oiReturnStatus)) in business>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.

assign vhFcComponent = vhBC.
<M-8 run GetKeyFields (input-output icTable (bcTableName), 
                       output vcPKey (ocPrimaryKey), 
                       output vcWork (ocAlternateKey), 
                       output vcWork (ocObjectID), 
                       output vcWork (ocObjectStatus), 
                       output viLocalReturn (oiReturnStatus)) in database>

<M-17 run BusinessClassActions
   (input  icClass (icClassShortname), 
    input  'CLOSE+STOP':U (icAction), 
    input  no (ilSubtransaction), 
    input-output viOpenC (biClassOpenCount), 
    input-output vhBC (bhClassInstanceHandle), 
    input-output viBC (biClassInstanceId), 
    input  '' (icDraftReference), 
    output viFcReturnSuper (oiReturnStatus)) in business>
if viLocalReturn <> 0
then oiReturnStatus = viLocalReturn.
if viLocalReturn < 0
then return.

if num-entries(vcPKey) <> viKeyCount
then do:
    <M-18 run SetMessage (input  'Invalid key column ($1)':U (icMessage), 
                      input  icKeyColumn (icArguments), 
                      input  '' (icFieldName), 
                      input  '' (icFieldValue), 
                      input  'S':U (icType), 
                      input  3 (iiSeverity), 
                      input  '' (icRowid), 
                      input  'BLF-261':U (icFcMsgNumber), 
                      input  '' (icFcExplanation), 
                      input  '' (icFcIdentification), 
                      input  '' (icFcContext), 
                      output viFcReturnSuper (oiReturnStatus)) in business>
    assign oiReturnStatus = -3.
    return.
end.

/* ================================================================= */
/* Update all records in resultset.                                  */
/* ================================================================= */
vcWork = "for each ":U + ihResultSetBuffer:name.
do viFcCount1 = 1 to viKeyCount:
    vcWork = vcWork + " by ":U + ihResultSetBuffer:name + ".":U + entry(viFcCount1,icKeyColumn).
end.
create query vhQuery in widget-pool "non-persistent".
vhQuery:forward-only = yes.
vhQuery:set-buffers(ihResultSetBuffer).
assign vlFcOk = vhQuery:query-prepare (vcWork).
if vlFcOk
then assign vlFcOk = vhQuery:query-open().
if vlFcOk = no
then return.
vhQuery:get-first().

DW_block:
do while not vhQuery:query-off-end:

    vlFcOk = yes.
    do viFcCount1 = 1 to viKeyCount:
        vcWork = string (vhKey[viFcCount1]:buffer-value).
        if vcWork = ? then vcWork = "".
        vcKeyValue = (if viFcCount1 = 1 then "" else vcKeyValue + chr(2)) + vcWork.
        if vcWork <> ""
        and vcWork <> "0":U
        then vlFcOk = no.
    end.

    if vcKeyValue <> vcOldValue
    then do:
        if vlFcOk
        then assign vcFieldValues = "".
        else do:
            do viFcCount1 = 1 to num-entries(vcPKey):
                assign vcWork = (if viFcCount1 = 1
                                 then "for each ":U + icTable + " where ":U
                                 else vcWork + " and ":U)
                              + icTable + ".":U + entry(viFcCount1,vcPKey) + " = ":U
                              + (if vhKey[viFcCount1]:data-type = "character":U
                                 then "'":U + entry(viFcCount1,vcKeyValue,chr(2)) + "'":U
                                 else if entry(viFcCount1,vcKeyValue,chr(2)) = ""
                                      then "?":U
                                      else entry(viFcCount1,vcKeyValue,chr(2))).
            end.

            <M-19 run StartPersistence (output vhFcComponent (ohPersistence), 
                            output viFcReturnSuper (oiReturnStatus)) in business>
            if viFcReturnSuper <> 0
            then oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0
            then leave DW_block.

            <M-12 run ReadDirect (input  icTable (icTableName), 
                      input  vcWork (icPrepare), 
                      input  vcFieldNames (icFieldList), 
                      output vcWork (ocValueList), 
                      input  {&TARGETPROCEDURE} (ihClass), 
                      output viFcReturnSuper (oiReturnStatus)) in persistence>
            if viFcReturnSuper <> 0
            then oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0
            then leave DW_block.

            if vlUseSingleItem = true
            then assign vcFieldValues = vcWork.
            else do viFcCount1 = 1 to num-entries(vcFieldNames):
                assign vcFieldValues = (if viFcCount1 = 1
                                        then ""
                                        else vcFieldValues + chr(2))
                                     + entry(viFcCount1,vcFieldNames) + chr(2)
                                     + entry(viFcCount1,vcFieldLabels,chr(2)) + chr(2)
                                     + entry(viFcCount1,vcWork,chr(2)).
            end.
        end.
    end.

    vhCustom:buffer-value = vcFieldValues.

    vhQuery:get-next().
end.

vhQuery:query-close().
delete object vhQuery.

if oiReturnStatus = -98
then oiReturnStatus = 0.