project QadFinancials > class BJournal > method ApiValidateJournal

Description

This method will validate the daybook that is passed in the input parameter:
- Does the journal with this companycode exist in the current company.
- Is this journal active
- When there is a journaltypelist passed as an input parameter, the type of the journal should be in that list.
- When there is a journalcontrol passed as an input parameter, the journal control should match the one that was passed.


Parameters


icJournalCodeinputcharacterJournalcode
icJournalTypeListinputcharacterList of JournalTypes. If this is left blank, the journaltype is not validated.
icJournalControlinputcharacterJournalControl. If it's left blank, then the control will not be validated.
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program9/bjournal.p)

/* =================================================================================================== */
/* Method      : ApiValidateJournal                                                                    */
/* Desc        : Validate journal                                                                      */
/* --------------------------------------------------------------------------------------------------- */
/* Params:  (I)  JournalCode          Code of journal to be validated                                  */
/*          (O)  JournalDescription   Description of journal                                           */
/* =================================================================================================== */

assign oiReturnStatus = -98.

/* =================================================================================================== */
/* Check for availability using prim query                                                             */
/* =================================================================================================== */
<Q-2 run JournalByJournalIDCodeType (all) (Read) (NoCache)
   (input viCompanyId, (CompanyId)
    input ?, (JournalID)
    input icJournalCode, (JournalCode)
    input ?, (JournalTypeCode)
    output dataset tqJournalByJournalIDCodeType) in BJournal >

find tqJournalByJournalIDCodeType where
     tqJournalByJournalIDCodeType.tcJournalCode = icJournalCode
     no-error.

assign vcMessage = '':U.

if icJournalCode = '':U or
   icJournalCode = ?
then do:
    assign vcMessage = trim(#T-81'Daybook code cannot be blank':255(807468123)T-81#)
           oiReturnStatus = -1.
    <M-37 run SetMessage
       (input  vcMessage (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QadFin-856445':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BJournal>
end.
else if not available tqJournalByJournalIDCodeType
then do:
     assign vcMessage = #T-3'Daybook &1 is not defined in the system.':150(60889)T-3#
            vcMessage = substitute(vcMessage, icJournalCode)
            oiReturnStatus = -1.
        <M-11 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  '':U (icRowid), 
            input  'QadFin-8551':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BJournal>
end.
else do:
    if tqJournalByJournalIDCodeType.tlJournalIsActive <> true
    then do:
        assign vcMessage = #T-4'Daybook &1 is not Active.':255(73483370)T-4#
               vcMessage = substitute(vcMessage, icJournalCode).

        <M-6 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  '':U (icRowid), 
            input  'QadFin-8447':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BJournal>
        assign oiReturnStatus = -1.
    end.
    
    if icJournalTypeList <> ?    and
       icJournalTypeList <> '':U and
       lookup(tqJournalByJournalIDCodeType.tcJournalTypeCode, icJournalTypeList, ',':U) = 0
    then do:
        /* Build a list of the valid daybook type codes, but use the user friendly translated strings */
        <M-38 run BuildJournalTypeListTr
           (output vcJournalTypeListTr (ocJournalTypeCodeListTr), 
            input  icJournalTypeList (icJournalTypeList), 
            output viFcReturnSuper (oiReturnStatus)) in BJournal>
    
        assign vcMessage = #T-8'Daybook &1 is not valid for daybook type &2.':150(413975693)T-8#
               vcMessage = substitute(vcMessage, icJournalCode, vcJournalTypeListTr).

        <M-7 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  '':U (icRowid), 
            input  'QadFin-8448':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BJournal>
        assign oiReturnStatus = -1.
    end.

    if icJournalControl <> ? and
       icJournalControl <> '':U and
       icJournalControl <> tqJournalByJournalIDCodeType.tcJournalControl
    then do:
        assign vcMessage = #T-10'Invalid Daybook Control for Daybook &1. Required daybook has to be control by &2.':255(591298640)T-10#
               vcMessage = substitute(vcMessage, icJournalCode, icJournalControl).

        <M-9 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  '':U (icRowid), 
            input  'QadFin-8449':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BJournal>
        assign oiReturnStatus = -1.
    end.
end.

/* =================================================================================================== */
/* Return                                                                                              */
/* =================================================================================================== */
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 = "BJournal".
create ttContext.
assign ttContext.propertyName = "methodName"
       ttContext.propertyValue = "ApiValidateJournal".
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/bjournal.apivalidatejournal.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icJournalCode = <parameter value>
       vhParameter::icJournalTypeList = <parameter value>
       vhParameter::icJournalControl = <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.