project BLF > class BReportVariant > method ApiGetVariantInformation

Description

Returns all data needed to initialize a report request form.


Parameters


icComponentNameinputcharactermandatory
icReportNameinputcharactermandatory
icUsrLogininputcharacteroptional (empty = use current user)
icRoleNameinputcharactermandatory
icCompanyCodeinputcharacteroptional (empty = use current company)
ovBReportVariantoutputdataset
tVariantListoutputtemp-table
tPrinterListoutputtemp-table
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program3/breportvariant.p)

if oiReturnStatus = 0
then oiReturnStatus = -98.

empty temp-table tVariantList.
empty temp-table tPrinterList.

if icComponentName = ""
or icComponentName = ?
or icReportName    = ""
or icReportName    = ?
or icRoleName      = ""
or icRoleName      = ?
then return.

/* ================================================================= */
/* Convert all codes into ID's                                       */
/* ================================================================= */
<Q-1 run BusActivityPrim (all) (Read) (NoCache)
   (input 0, (BusActivityID)
    input icReportName, (BusActivityCode)
    input icComponentName, (BusComponentCode)
    output dataset tqBusActivityPrim) in BBusinessComponent >
find first tqBusActivityPrim no-error.
if not available tqBusActivityPrim
then do:
    <M-2 run SetMessage
          (input  'Invalid report name.' (icMessage), 
           input  '' (icArguments), 
           input  '' (icFieldName), 
           input  '' (icFieldValue), 
           input  'S' (icType), 
           input  3 (iiSeverity), 
           input  '' (icRowid), 
           input  'BLF-153':U (icFcMsgNumber), 
           input  '' (icFcExplanation), 
           input  '' (icFcIdentification), 
           input  '' (icFcContext), 
           output viFcReturnSuper (oiReturnStatus)) in BReportVariant>
    oiReturnStatus = -3.
    return.
end.

if icCompanyCode = ""
or icCompanyCode = ?
then viFilterCompanyID = viCompanyId.
else do:
    <Q-3 run CompanyPrim (all) (Read) (NoCache)
       (input 0, (LookupCompanyId)
        input icCompanyCode, (CompanyCode)
        output dataset tqCompanyPrim) in BCompany >
    find first tqCompanyPrim no-error.
    if available tqCompanyPrim
    then viFilterCompanyID = tqCompanyPrim.tiCompany_ID.
    else do:
        <M-4 run SetMessage
          (input  'Invalid company code.' (icMessage), 
           input  '' (icArguments), 
           input  '' (icFieldName), 
           input  '' (icFieldValue), 
           input  'S' (icType), 
           input  3 (iiSeverity), 
           input  '' (icRowid), 
           input  'BLF-154':U (icFcMsgNumber), 
           input  '' (icFcExplanation), 
           input  '' (icFcIdentification), 
           input  '' (icFcContext), 
           output viFcReturnSuper (oiReturnStatus)) in BReportVariant>
        oiReturnStatus = -3.
        return.
    end.
end.

<Q-5 run RolePrim (all) (Read) (NoCache)
   (input 0, (RoleID)
    input icRoleName, (RoleName)
    output dataset tqRolePrim) in BRole >
find first tqRolePrim no-error.
if available tqRolePrim
then viFilterRoleID = tqRolePrim.tiRole_ID.
else do:
    <M-6 run SetMessage
          (input  'Invalid role name.' (icMessage), 
           input  '' (icArguments), 
           input  '' (icFieldName), 
           input  '' (icFieldValue), 
           input  'S' (icType), 
           input  3 (iiSeverity), 
           input  '' (icRowid), 
           input  'BLF-155':U (icFcMsgNumber), 
           input  '' (icFcExplanation), 
           input  '' (icFcIdentification), 
           input  '' (icFcContext), 
           output viFcReturnSuper (oiReturnStatus)) in BReportVariant>
    oiReturnStatus = -3.
    return.
end.

if icUsrLogin = ""
or icUsrLogin = ?
then viFilterUserID = viUsrId.
else do:
    <Q-7 run UserPrim (all) (Read) (NoCache)
       (input 0, (UsrId)
        input icUsrLogin, (UsrLogin)
        output dataset tqUserPrim) in BUser >
    find first tqUserPrim no-error.
    if available tqUserPrim
    then viFilterUserID = tqUserPrim.tiUsr_ID.
    else do:
        <M-8 run SetMessage
          (input  'Invalid user name.' (icMessage), 
           input  '' (icArguments), 
           input  '' (icFieldName), 
           input  '' (icFieldValue), 
           input  'S' (icType), 
           input  3 (iiSeverity), 
           input  '' (icRowid), 
           input  'BLF-156':U (icFcMsgNumber), 
           input  '' (icFcExplanation), 
           input  '' (icFcIdentification), 
           input  '' (icFcContext), 
           output viFcReturnSuper (oiReturnStatus)) in BReportVariant>
        oiReturnStatus = -3.
        return.
    end.
end.

/* ================================================================= */
/* Get available printer list                                        */
/* ================================================================= */
<Q-14 run RptPrinterByName (all) (Read) (NoCache)  (output dataset tqRptPrinterByName) in BPrinter >

for each tqRptPrinterByName:
    create tPrinterList.

    assign tPrinterList.tcRptPrinterName      = tqRptPrinterByName.tcRptPrinterName
           tPrinterList.tlRptPrinterIsDefault = tqRptPrinterByName.tlRptPrinterIsDefault.
end.

empty temp-table tqRptPrinterByName.

/* ================================================================= */
/* Get variant list                                                  */
/* ================================================================= */
<Q-9 run ReportVariants (all) (Read) (NoCache)
   (input viFilterCompanyID, (CompanyId)
    input viFilterUserID, (UserID)
    input viFilterRoleID, (RoleID)
    input tqBusActivityPrim.tiBusActivity_ID, (ReportID)
    input '', (BusComponentCode)
    input '', (BusComponentLabel)
    output dataset tqReportVariants) in BReportVariant>
for each tqReportVariants:
    /* ignore last used */
    if tqReportVariants.tcRptRequestName begins {&STOREDSEARCH-LAST-USED} then next.
    create tVariantList.
    assign tVariantList.tcRptRequestName = tqReportVariants.tcRptRequestName
           tVariantList.tiRptRequest_ID  = tqReportVariants.tiRptRequest_ID.
end.

/* ================================================================= */
/* Load default variant                                              */
/* ================================================================= */
find first tqReportVariants where
           tqReportVariants.tcRptRequestName = {&STOREDSEARCH-LAST-USED} + "_" + vcUserLogin no-error.
if not available tqReportVariants
then find first tqReportVariants where
                tqReportVariants.tcRptRequestName = {&STOREDSEARCH-CUSTOMER-DEFAULT} no-error.
if not available tqReportVariants
then find first tqReportVariants where
                tqReportVariants.tcRptRequestName = {&STOREDSEARCH-FACTORY-DEFAULT} no-error.
if available tqReportVariants
then do:
    <M-12 run DataLoad
       (input  '' (icRowids), 
        input  string(tqReportVariants.tiRptRequest_ID) (icPkeys), 
        input  '' (icObjectIds), 
        input  '' (icFreeform), 
        input  no (ilKeepPrevious), 
        output viFcReturnSuper (oiReturnStatus)) in BReportVariant>
end.
else do:
    <M-13 run ClearData  (output viFcReturnSuper (oiReturnStatus)) in BReportVariant>
end.
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.

empty temp-table tqReportVariants.

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 = "BReportVariant".
create ttContext.
assign ttContext.propertyName = "methodName"
       ttContext.propertyValue = "ApiGetVariantInformation".
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/breportvariant.apigetvariantinformation.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icComponentName = <parameter value>
       vhParameter::icReportName = <parameter value>
       vhParameter::icUsrLogin = <parameter value>
       vhParameter::icRoleName = <parameter value>
       vhParameter::icCompanyCode = <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.