project QadFinancials > class BDebtor > method ApiGetCustomFields

Description

Returns a temp table ith the Custom fields information and the values


Parameters


iiDebtorIDinputinteger
icDebtorCodeinputcharacter
tDebtorCustomFieldoutputtemp-table
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program8/bdebtor.p)

assign oiReturnStatus = -98.

empty temp-table tDebtorCustomField.

main-block: do:

if (iiDebtorID   = 0    or
    iiDebtorID   = ?)   and
   (icDebtorCode = '':U or
    icDebtorCode = ?)
then leave main-block.

if iiDebtorID = 0 or
   iiDebtorID = ?
then do:
    if icDebtorCode <> '':U and
       icDebtorCode <> ?
    then do:
        <Q-2 run DebtorPrim (all) (Read) (NoCache)
          (input viCompanyId, (CompanyId)
           input icDebtorCode, (DebtorCode)
           input ?, (Debtor_ID)
           output dataset tqDebtorPrim) in BDebtor >
        find tqDebtorPrim where
             tqDebtorPrim.tcDebtorCode = icDebtorCode
             no-lock no-error.
        if not available tqDebtorPrim
        then leave main-block.

        assign iiDebtorID = tqDebtorPrim.tiDebtor_ID.
    end.
end.

<Q-8 run DebtorByCompany (all) (Read) (NoCache)
          (input viCompanyId, (CompanyId)
           input iiDebtorID, (DebtorID)
           output dataset tqDebtorByCompany) in BDebtor >

find tqDebtorByCompany where
     tqDebtorByCompany.tiDebtor_ID = iiDebtorID
     no-lock no-error.

if not available tqDebtorByCompany
then leave main-block.

/* ====================================== */
/* Return the custom fields and the value */
/* ====================================== */

<Q-1 run GetCustomFieldsForTable (all) (Read) (NoCache)
   (input 'tDebtor':U, (TableName)
    input '', (ComponentName)
    output dataset tqCustomFieldsForTable) in BCustomField >

for each tqCustomFieldsForTable no-lock:
    create tDebtorCustomField.
    assign tDebtorCustomField.CustomFieldColumnLabel         = tqCustomFieldsForTable.tcCustomFieldColumnLabel   
           tDebtorCustomField.CustomFieldDataType            = tqCustomFieldsForTable.tcCustomFieldDataType
           tDebtorCustomField.CustomFieldDescription         = tqCustomFieldsForTable.tcCustomFieldDescription
           tDebtorCustomField.CustomFieldDisplayFormat       = tqCustomFieldsForTable.tcCustomFieldDisplayFormat
           tDebtorCustomField.CustomFieldDisplayLength       = tqCustomFieldsForTable.tiCustomFieldDisplayLength
           tDebtorCustomField.CustomFieldFieldName           = tqCustomFieldsForTable.tcCustomFieldFieldName    
           tDebtorCustomField.CustomFieldIsMandatory         = tqCustomFieldsForTable.tlCustomFieldIsMandatory
           tDebtorCustomField.CustomFieldPrecision           = tqCustomFieldsForTable.tiCustomFieldPrecision
           tDebtorCustomField.CustomFieldSideLabel           = tqCustomFieldsForTable.tcCustomFieldSideLabel       
           tDebtorCustomField.CustomFieldUIControlType       = tqCustomFieldsForTable.tcCustomFieldUIControlType
           tDebtorCustomField.CustomFieldValueListChoice     = tqCustomFieldsForTable.tcCustomFieldValueListChoice
           tDebtorCustomField.CustomField_ID                 = tqCustomFieldsForTable.tiCustomField_ID
           tDebtorCustomField.StoredSearch_ID                = tqCustomFieldsForTable.tiStoredSearch_ID
           tDebtorCustomField.tc_Rowid                       = string(rowid(tDebtorCustomField)).

    assign vcCustomFieldFieldNameTemp = substring(tqCustomFieldsForTable.tcCustomFieldFieldName,index(tqCustomFieldsForTable.tcCustomFieldFieldName,'.':U) + 1, -1,'CHARACTER':U).      
    
    /*Short*/
    if vcCustomFieldFieldNameTemp = 'CustomShort0':U
    then do:
        assign tDebtorCustomField.tcValueString = tqDebtorByCompany.tcCustomShort0
               tDebtorCustomField.tcValueUsed   = 'tcValueString':U.
    end.
    if vcCustomFieldFieldNameTemp = 'CustomShort1':U
    then do:
        assign tDebtorCustomField.tcValueString = tqDebtorByCompany.tcCustomShort1
               tDebtorCustomField.tcValueUsed   = 'tcValueString':U.
    end.
    if vcCustomFieldFieldNameTemp = 'CustomShort2':U
    then do:
        assign tDebtorCustomField.tcValueString = tqDebtorByCompany.tcCustomShort2
               tDebtorCustomField.tcValueUsed   = 'tcValueString':U.
    end.
    if vcCustomFieldFieldNameTemp = 'CustomShort3':U
    then do:
        assign tDebtorCustomField.tcValueString = tqDebtorByCompany.tcCustomShort3
               tDebtorCustomField.tcValueUsed   = 'tcValueString':U.
    end.
    if vcCustomFieldFieldNameTemp = 'CustomShort4':U
    then do:
        assign tDebtorCustomField.tcValueString = tqDebtorByCompany.tcCustomShort4
               tDebtorCustomField.tcValueUsed   = 'tcValueString':U.
    end.
    if vcCustomFieldFieldNameTemp = 'CustomShort5':U
    then do:
        assign tDebtorCustomField.tcValueString = tqDebtorByCompany.tcCustomShort5
               tDebtorCustomField.tcValueUsed   = 'tcValueString':U.
    end.
    if vcCustomFieldFieldNameTemp = 'CustomShort6':U
    then do:
        assign tDebtorCustomField.tcValueString = tqDebtorByCompany.tcCustomShort6
               tDebtorCustomField.tcValueUsed   = 'tcValueString':U.
    end.
    if vcCustomFieldFieldNameTemp = 'CustomShort7':U
    then do:
        assign tDebtorCustomField.tcValueString = tqDebtorByCompany.tcCustomShort7
               tDebtorCustomField.tcValueUsed   = 'tcValueString':U.
    end.
    if vcCustomFieldFieldNameTemp = 'CustomShort8':U
    then do:
        assign tDebtorCustomField.tcValueString = tqDebtorByCompany.tcCustomShort8
               tDebtorCustomField.tcValueUsed   = 'tcValueString':U.
    end.
    if vcCustomFieldFieldNameTemp = 'CustomShort9':U
    then do:
        assign tDebtorCustomField.tcValueString = tqDebtorByCompany.tcCustomShort9
               tDebtorCustomField.tcValueUsed   = 'tcValueString':U.
    end.
    /*Combo*/
    if vcCustomFieldFieldNameTemp = 'CustomCombo0':U
    then do:
        assign tDebtorCustomField.tcValueString = tqDebtorByCompany.tcCustomCombo0
               tDebtorCustomField.tcValueUsed   = 'tcValueString':U.
    end.
    if vcCustomFieldFieldNameTemp = 'CustomCombo1':U
    then do:
        assign tDebtorCustomField.tcValueString = tqDebtorByCompany.tcCustomCombo1
               tDebtorCustomField.tcValueUsed   = 'tcValueString':U.
    end.
    if vcCustomFieldFieldNameTemp = 'CustomCombo2':U
    then do:
        assign tDebtorCustomField.tcValueString = tqDebtorByCompany.tcCustomCombo2
               tDebtorCustomField.tcValueUsed   = 'tcValueString':U.
    end.
    if vcCustomFieldFieldNameTemp = 'CustomCombo3':U
    then do:
        assign tDebtorCustomField.tcValueString = tqDebtorByCompany.tcCustomCombo3
               tDebtorCustomField.tcValueUsed   = 'tcValueString':U.
    end.
    if vcCustomFieldFieldNameTemp = 'CustomCombo4':U
    then do:
        assign tDebtorCustomField.tcValueString = tqDebtorByCompany.tcCustomCombo4
               tDebtorCustomField.tcValueUsed   = 'tcValueString':U.
    end.
    if vcCustomFieldFieldNameTemp = 'CustomCombo5':U
    then do:
        assign tDebtorCustomField.tcValueString = tqDebtorByCompany.tcCustomCombo5
               tDebtorCustomField.tcValueUsed   = 'tcValueString':U.
    end.
    if vcCustomFieldFieldNameTemp = 'CustomCombo6':U
    then do:
        assign tDebtorCustomField.tcValueString = tqDebtorByCompany.tcCustomCombo6
               tDebtorCustomField.tcValueUsed   = 'tcValueString':U.
    end.
    if vcCustomFieldFieldNameTemp = 'CustomCombo7':U
    then do:
        assign tDebtorCustomField.tcValueString = tqDebtorByCompany.tcCustomCombo7
               tDebtorCustomField.tcValueUsed   = 'tcValueString':U.
    end.
    if vcCustomFieldFieldNameTemp = 'CustomCombo8':U
    then do:
        assign tDebtorCustomField.tcValueString = tqDebtorByCompany.tcCustomCombo8
               tDebtorCustomField.tcValueUsed   = 'tcValueString':U.
    end.
    if vcCustomFieldFieldNameTemp = 'CustomCombo9':U
    then do:
        assign tDebtorCustomField.tcValueString = tqDebtorByCompany.tcCustomCombo9
               tDebtorCustomField.tcValueUsed   = 'tcValueString':U.
    end.
    /*Long*/
    if vcCustomFieldFieldNameTemp = 'CustomLong0':U
    then do:
        assign tDebtorCustomField.tcValueString = tqDebtorByCompany.tcCustomLong0
               tDebtorCustomField.tcValueUsed   = 'tcValueString':U.
    end.
    if vcCustomFieldFieldNameTemp = 'CustomLong1':U
    then do:
        assign tDebtorCustomField.tcValueString = tqDebtorByCompany.tcCustomLong1
               tDebtorCustomField.tcValueUsed   = 'tcValueString':U.
    end.
    /*Note*/
    if vcCustomFieldFieldNameTemp = 'CustomNote':U
    then do:
        assign tDebtorCustomField.tcValueString = tqDebtorByCompany.tcCustomNote
               tDebtorCustomField.tcValueUsed   = 'tcValueString':U.
    end.
    /*Date*/
    if vcCustomFieldFieldNameTemp = 'CustomDate0':U
    then do:
        assign tDebtorCustomField.ttValueDate = tqDebtorByCompany.ttCustomDate0
               tDebtorCustomField.tcValueUsed = 'ttValueDate':U.
    end.
    if vcCustomFieldFieldNameTemp = 'CustomDate1':U
    then do:
        assign tDebtorCustomField.ttValueDate = tqDebtorByCompany.ttCustomDate1
               tDebtorCustomField.tcValueUsed = 'ttValueDate':U.
    end.
    if vcCustomFieldFieldNameTemp = 'CustomDate2':U
    then do:
        assign tDebtorCustomField.ttValueDate = tqDebtorByCompany.ttCustomDate2
               tDebtorCustomField.tcValueUsed = 'ttValueDate':U.
    end.
    if vcCustomFieldFieldNameTemp = 'CustomDate3':U
    then do:
        assign tDebtorCustomField.ttValueDate = tqDebtorByCompany.ttCustomDate3
               tDebtorCustomField.tcValueUsed = 'ttValueDate':U.
    end.
    if vcCustomFieldFieldNameTemp = 'CustomDate4':U
    then do:
        assign tDebtorCustomField.ttValueDate = tqDebtorByCompany.ttCustomDate4
               tDebtorCustomField.tcValueUsed = 'ttValueDate':U.
    end.
    /*Integer*/
    if vcCustomFieldFieldNameTemp = 'CustomInteger0':U
    then do:
        assign tDebtorCustomField.tiValueInt  = tqDebtorByCompany.tiCustomInteger0
               tDebtorCustomField.tcValueUsed = 'tiValueInt':U.
    end.
    if vcCustomFieldFieldNameTemp = 'CustomInteger1':U
    then do:
        assign tDebtorCustomField.tiValueInt  = tqDebtorByCompany.tiCustomInteger1
               tDebtorCustomField.tcValueUsed = 'tiValueInt':U.
    end.
    if vcCustomFieldFieldNameTemp = 'CustomInteger2':U
    then do:
        assign tDebtorCustomField.tiValueInt  = tqDebtorByCompany.tiCustomInteger2
               tDebtorCustomField.tcValueUsed = 'tiValueInt':U.
    end.
    if vcCustomFieldFieldNameTemp = 'CustomInteger3':U
    then do:
        assign tDebtorCustomField.tiValueInt  = tqDebtorByCompany.tiCustomInteger3
               tDebtorCustomField.tcValueUsed = 'tiValueInt':U.
    end.
    if vcCustomFieldFieldNameTemp = 'CustomInteger4':U
    then do:
        assign tDebtorCustomField.tiValueInt  = tqDebtorByCompany.tiCustomInteger4
               tDebtorCustomField.tcValueUsed = 'tiValueInt':U.
    end.
    /*Decimal*/
    if vcCustomFieldFieldNameTemp = 'CustomDecimal0':U
    then do:
        assign tDebtorCustomField.tdValueDec  = tqDebtorByCompany.tdCustomDecimal0
               tDebtorCustomField.tcValueUsed = 'tdValueDec':U.
    end.
    if vcCustomFieldFieldNameTemp = 'CustomDecimal1':U
    then do:
        assign tDebtorCustomField.tdValueDec  = tqDebtorByCompany.tdCustomDecimal1
               tDebtorCustomField.tcValueUsed = 'tdValueDec':U.
    end.
    if vcCustomFieldFieldNameTemp = 'CustomDecimal2':U
    then do:
        assign tDebtorCustomField.tdValueDec  = tqDebtorByCompany.tdCustomDecimal2
               tDebtorCustomField.tcValueUsed = 'tdValueDec':U.
    end.
    if vcCustomFieldFieldNameTemp = 'CustomDecimal3':U
    then do:
        assign tDebtorCustomField.tdValueDec  = tqDebtorByCompany.tdCustomDecimal3
               tDebtorCustomField.tcValueUsed = 'tdValueDec':U.
    end.
    if vcCustomFieldFieldNameTemp = 'CustomDecimal4':U
    then do:
        assign tDebtorCustomField.tdValueDec  = tqDebtorByCompany.tdCustomDecimal4
               tDebtorCustomField.tcValueUsed = 'tdValueDec':U.
    end.
       
end.

end. /*main-block*/

if oiReturnStatus = -98
then assign oiReturnStatus = 0.


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 = "BDebtor".
create ttContext.
assign ttContext.propertyName = "methodName"
       ttContext.propertyValue = "ApiGetCustomFields".
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/bdebtor.apigetcustomfields.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::iiDebtorID = <parameter value>
       vhParameter::icDebtorCode = <parameter value>.

/* 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.