project QadFinancials > class BCInvoice > method ApiGetIdentification

Description

This method gives the possibility to ask the system to get identification information (primary key, alternate key, rowid of the main table of the object), based on any of the three keys as input.

This method must be overwritten when the alternate key cannot be defined unambiguously by CB. So for supplier invoice we have two alternate keys : company, posting year, journal and voucher AND registration number


Parameters


bcPrimaryKeyinput-outputcharacterThe primary key value of the main table of the object.
In case of a combined primary key, the different values should be separated with chr(2)
bcAlternateKeyinput-outputcharacterThe alternate key value of the main table of the object.
In case of a combined alternate key, the different values should be separated with chr(2)
bcRowidinput-outputcharacterThe rowid of the main table record of the object.
biObjectIdinput-outputintegerIdentity field of the main table of the object.
ocObjectStatusValuesoutputcharacterchr(2) seperated list of value of object status fields
ocObjectStatusFieldNamesoutputcharacterComma seperated list of field name of object status fields
ocPrimaryKeyFieldNamesoutputcharacterList of primary key fields of the main table of the object.
This is a comma separated list.
ocAlternateKeyFieldNamesoutputcharacterList of alternate key fields (names) of the main table of the object.
This is a comma separated list.
ocAlternateKeyFieldLabelsoutputcharacterList of alternate key fields (translated labels) of the main table of the object.
This is a chr(2) separated list.
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program/bcinvoice.p)

<ANCESTOR-CODE>

if (bcPrimaryKey   <> "":U and bcPrimaryKey   <> ?)    or
   (bcAlternateKey <> "":U and bcAlternateKey <> ?)    or
   (bcRowid        <> "":U and bcRowid        <> ?)    or
   (biObjectId     <> 0    and biObjectId     <> ?)

then do:  
     assign oiReturnStatus            = -98
            ocPrimaryKeyFieldNames    = "tCInvoice.CInvoice_ID":U
            ocAlternateKeyFieldNames  = 
            "tCInvoice.CInvoicePostingYear,tCInvoice.tcJournalCode,tCInvoice.CInvoiceVoucher":U
            ocAlternateKeyFieldLabels = trim(#T-5'GL Cal Year':11(1116)T-5#) + chr(2)
                                 + trim(#T-6'Daybook Code':15(1117)T-6#) + chr(2)
                                 + trim(#T-7'Voucher':12(999890235)T-7#).  /* column labels */

if num-entries(bcAlternateKey,chr(2)) = 3
then do:
    <Q-8 run CInvoiceByCyIDYearJrnlVchr (all) (Read) (NoCache)
       (input viCompanyId, (CompanyId)
        input 0, (CInvoiceId)
        input integer(entry(1,bcAlternateKey,chr(2))), (PeriodYear)
        input 0, (JournalId)
        input entry(2,bcAlternateKey,chr(2)), (JournalCode)
        input integer(entry(3,bcAlternateKey,chr(2))), (Voucher)
        output dataset tqCInvoiceByCyIDYearJrnlVchr) in BCInvoice >
    find first tqCInvoiceByCyIDYearJrnlVchr no-error.
    if available tqCInvoiceByCyIDYearJrnlVchr
    then assign bcPrimaryKey   = string(tqCInvoiceByCyIDYearJrnlVchr.tiCInvoice_ID)
                bcAlternateKey = string(tqCInvoiceByCyIDYearJrnlVchr.tiPeriodYear) + chr(2)
                               + tqCInvoiceByCyIDYearJrnlVchr.tcJournalCode + chr(2)
                               + string(tqCInvoiceByCyIDYearJrnlVchr.tiCInvoiceVoucher)
                bcRowid        = entry (1,tqCInvoiceByCyIDYearJrnlVchr.tc_Rowid)
                biObjectId     = tqCInvoiceByCyIDYearJrnlVchr.tiCInvoice_ID
                ocObjectStatusFieldNames = "tCInvoice.CInvoiceIsOpen,tCInvoice.CInvoiceIsSelected,tCInvoice.CInvoiceAllocationStatus,tCInvoice.CInvoiceIsInvoiceApproved,tCInvoice.CInvoiceIsLockPayment,tCInvoice.CInvoiceIsInitialStatus":U
                ocObjectStatusValues     = string(tqCInvoiceByCyIDYearJrnlVchr.tlCInvoiceIsOpen) + chr(2) +
                                           string(tqCInvoiceByCyIDYearJrnlVchr.tlCInvoiceIsSelected) + chr(2) +
                                           tqCInvoiceByCyIDYearJrnlVchr.tcCInvoiceAllocationStatus + chr(2) +
                                           string(tqCInvoiceByCyIDYearJrnlVchr.tlCInvoiceIsInvoiceApproved) + chr(2) +
                                           string(tqCInvoiceByCyIDYearJrnlVchr.tlCInvoiceIsLockPayment)+ chr(2) +
                                           string(tqCInvoiceByCyIDYearJrnlVchr.tlCInvoiceIsInitialStatus).
end.
else do:
    if  bcPrimaryKey <> ""
    and bcPrimaryKey <> ?
    then assign biObjectId = integer(bcPrimaryKey)
                bcRowid    = "".
    
    if  biObjectId <> 0
    and biObjectId <> ?
    then do:
        <Q-9 run CInvoiceByCyIDYearJrnlVchr (all) (Read) (NoCache)
           (input 0, (CompanyId)
            input biObjectId, (CInvoiceId)
            input 0, (PeriodYear)
            input 0, (JournalId)
            input '':U, (JournalCode)
            input 0, (Voucher)
            output dataset tqCInvoiceByCyIDYearJrnlVchr) in BCInvoice >
        find first tqCInvoiceByCyIDYearJrnlVchr no-error.
        if available tqCInvoiceByCyIDYearJrnlVchr
        then assign bcPrimaryKey   = string(tqCInvoiceByCyIDYearJrnlVchr.tiCInvoice_ID)
                    bcAlternateKey = string(tqCInvoiceByCyIDYearJrnlVchr.tiPeriodYear) + chr(2)
                                   + tqCInvoiceByCyIDYearJrnlVchr.tcJournalCode + chr(2)
                                   + string(tqCInvoiceByCyIDYearJrnlVchr.tiCInvoiceVoucher)
                    bcRowid        = entry (1,tqCInvoiceByCyIDYearJrnlVchr.tc_Rowid)
                    biObjectId     = tqCInvoiceByCyIDYearJrnlVchr.tiCInvoice_ID
                    ocObjectStatusFieldNames = "tCInvoice.CInvoiceIsOpen,tCInvoice.CInvoiceIsSelected,tCInvoice.CInvoiceAllocationStatus,tCInvoice.CInvoiceIsInvoiceApproved,tCInvoice.CInvoiceIsLockPayment,tCInvoice.CInvoiceIsInitialStatus":U
                    ocObjectStatusValues     = string(tqCInvoiceByCyIDYearJrnlVchr.tlCInvoiceIsOpen) + chr(2) +
                                               string(tqCInvoiceByCyIDYearJrnlVchr.tlCInvoiceIsSelected) + chr(2) +
                                               tqCInvoiceByCyIDYearJrnlVchr.tcCInvoiceAllocationStatus + chr(2) +
                                               string(tqCInvoiceByCyIDYearJrnlVchr.tlCInvoiceIsInvoiceApproved) + chr(2) +
                                               string(tqCInvoiceByCyIDYearJrnlVchr.tlCInvoiceIsLockPayment) + chr(2) +
                                               string(tqCInvoiceByCyIDYearJrnlVchr.tlCInvoiceIsInitialStatus).
    end.
    else if  bcRowid <> ""
         and bcRowid <> ?
    then do:
        <M-3 run DataLoad (input  bcRowid (icRowids), 
                   input  '' (icPkeys), 
                   input  '' (icObjectIds), 
                   input  '' (icFreeform), 
                   input  no (ilKeepPrevious), 
                   output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
        if viFcReturnSuper <> 0
        then oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0
        then return.
    
        find first tCInvoice.
        assign bcPrimaryKey   = string(tCInvoice.CInvoice_ID)
               bcAlternateKey = string(tCInvoice.CInvoicePostingYear) + chr(2)
                              + tCInvoice.tcJournalCode + chr(2)
                              + string(tCInvoice.CInvoiceVoucher)
               bcRowid        = tCInvoice.tc_Rowid
               biObjectId     = tCInvoice.CInvoice_ID
               ocObjectStatusFieldNames = "tCInvoice.CInvoiceIsOpen,tCInvoice.CInvoiceIsSelected,tCInvoice.CInvoiceAllocationStatus,tCInvoice.CInvoiceIsInvoiceApproved,tCInvoice.CInvoiceIsLockPayment,tCInvoice.CInvoiceIsInitialStatus":U
               ocObjectStatusValues     = string(tqCInvoiceByCyIDYearJrnlVchr.tlCInvoiceIsOpen) + chr(2) +
                                          string(tqCInvoiceByCyIDYearJrnlVchr.tlCInvoiceIsSelected) + chr(2) +
                                          tqCInvoiceByCyIDYearJrnlVchr.tcCInvoiceAllocationStatus + chr(2) +
                                          string(tqCInvoiceByCyIDYearJrnlVchr.tlCInvoiceIsInvoiceApproved) + chr(2) +
                                          string(tqCInvoiceByCyIDYearJrnlVchr.tlCInvoiceIsLockPayment) + chr(2) +
                                          string(tqCInvoiceByCyIDYearJrnlVchr.tlCInvoiceIsInitialStatus).
      end.
  end.
end.
if oiReturnStatus = -98
then 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 = "BCInvoice".
create ttContext.
assign ttContext.propertyName = "methodName"
       ttContext.propertyValue = "ApiGetIdentification".
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 = "".

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