project QadFinancials > class BMfgMessage > method ApiGetSimpleMessage

Description

Gets the message description from MFG/PRO for a specified error number and returns the message in the current language. The error message text is returned in the ocMessageText parameter.


Parameters


iiMessageNumberinputintegerThe number of the message to retrieve from the MFG/PRO error table.
ocMessageTextoutputcharacterThe translated text of the requested error message.
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method MfgDatabaseComponent.SetSimpleMessage
method BMfgMessage.ApiGetComplexMessage


program code (program3/bmfgmessage.p)

/* Language mapping is no longer needed as Mfg and Fin languages are equal. */
assign
    vcMfgLanguage  = current-language
    ocMessageText  = ""
    oiReturnStatus = -98.

/*
* Get the Message details from MFG/PRO for the requested Error Number,
* using the language of the current financials session.
*/
<Q-2 run MfgMessageByNumber (all) (Read) (NoCache)
          (input iiMessageNumber, (MessageNumber)
           input vcMfgLanguage, (LanguageCode)
           output dataset tqMfgMessageByNumber) in BMfgMessage >

/*
* Get the requested message record from the temp table returned 
* by the query and set the ocMessageText value to the message
* text that is stored in MFG/PRO.
*/
find first tqMfgMessageByNumber
     where tqMfgMessageByNumber.tcmsg_lang = vcMfgLanguage
       and tqMfgMessageByNumber.timsg_nbr  = iiMessageNumber
     no-error.

if available(tqMfgMessageByNumber) then do:   
    assign
        ocMessageText = tqMfgMessageByNumber.tcmsg_desc.
end.

/*
* If the query did not return message requested and the current language is
* not :US" then we will go and see if the messages exists in the default 
* "US" langauge.
*/
else if not available tqMfgMessageByNumber and
   vcMfgLanguage <> "US":U
then do:

    <Q-3 run MfgMessageByNumber (all) (Read) (NoCache)
          (input iiMessageNumber, (MessageNumber)
           input 'US':U, (LanguageCode)
           output dataset tqMfgMessageByNumber) in BMfgMessage >
    
    for first tqMfgMessageByNumber 
         where tqMfgMessageByNumber.tcmsg_lang = vcMfgLanguage
           and tqMfgMessageByNumber.timsg_nbr  = iiMessageNumber:
        
        assign
            ocMessageText = tqMfgMessageByNumber.tcmsg_desc.

    end. /* first tqMfgMessageByNumber */

    /*
    * If we still have not been able to find an error message the
    * we just return the error number as the error message.
    * This should never happen in a released system but may very 
    * easily happen during the development lifecycle.
    */
    if ocMessageText = "" or
       ocMessageText = ?
    then
        assign
            ocMessageText = string(iiMessageNumber).

end. /* not available tqMfgMessageByNumber */

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 = "BMfgMessage".
create ttContext.
assign ttContext.propertyName = "methodName"
       ttContext.propertyValue = "ApiGetSimpleMessage".
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/bmfgmessage.apigetsimplemessage.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::iiMessageNumber = <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.