project BLF > class BStoredSearch > method ApiGetStoredSearchDeletion

Description

Returns a list of stored searches, for usage by the delete stored search activity.


Parameters


icNameinputcharacter
icReferenceinputcharacter
iiAccessLevelinputinteger
iiCurrentRoleIDinputinteger
tStoredSearchDeletionoutputtemp-table
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program3/bstoredsearch.p)

if oiReturnStatus = 0
then oiReturnStatus = -98.

empty temp-table tStoredSearchDeletion.

if icName = {&STOREDSEARCH-FACTORY-DEFAULT-TR}
then icName = {&STOREDSEARCH-FACTORY-DEFAULT}.
if icName = {&STOREDSEARCH-CUSTOMER-DEFAULT-TR}
then icName = {&STOREDSEARCH-CUSTOMER-DEFAULT}.

assign vctemp = if can-do ("mfg,FacDef":U,vcUserLogin)
                then "":U
                else vcUserLogin.
                
/* cache the translations */
assign vcAccessLevelRole-TR   = {&CONTROLPROPERTYLAYERTYPE-ROLE-TR}
       vcAccessLevelSystem-TR = {&CONTROLPROPERTYLAYERTYPE-SYSTEM-TR}
       vcAccessLevelUser-TR   = {&CONTROLPROPERTYLAYERTYPE-USER-TR}.

/* ================================================================= */
/* Run query to retrieve stored searches                             */
/* ================================================================= */
<Q-1 run GetStoredSearchDeletion (all) (Read) (NoCache)
   (input icName, (Name)
    input icReference, (Reference)
    input viCompanyId, (CompanyId)

    input vctemp, (Login)
    output dataset tqGetStoredSearchDeletion) in BStoredSearch >

/* ================================================================= */
/* Copy results to output                                            */
/* ================================================================= */
for each tqGetStoredSearchDeletion:

    if vcTemp <> "":U and
       tqGetStoredSearchDeletion.tcStoredSearchName = {&STOREDSEARCH-FACTORY-DEFAULT}
    then next.
    
    if iiAccessLevel = {&CONTROLPROPERTYLAYERTYPE-USER}
    and tqGetStoredSearchDeletion.tiUsr_ID <> viUsrId
    then next.

    if iiAccessLevel = {&CONTROLPROPERTYLAYERTYPE-ROLE}
    and iiCurrentRoleID <> 0
    and iiCurrentRoleID <> ?
    and tqGetStoredSearchDeletion.tiRole_ID <> iiCurrentRoleID
    then next.

    if iiAccessLevel = {&CONTROLPROPERTYLAYERTYPE-ROLE}
    and (iiCurrentRoleID = 0 or iiCurrentRoleID = ?)
    and tqGetStoredSearchDeletion.tiRole_ID = 0
    then next.

    if iiAccessLevel = {&CONTROLPROPERTYLAYERTYPE-SYSTEM}
    and (tqGetStoredSearchDeletion.tiUsr_ID <> 0 or
         tqGetStoredSearchDeletion.tiRole_ID <> 0)
    then next.

    create tStoredSearchDeletion.
    assign tStoredSearchDeletion.tcStoredSearchName      = tqGetStoredSearchDeletion.tcStoredSearchName
           tStoredSearchDeletion.tcStoredSearchReference = tqGetStoredSearchDeletion.tcStoredSearchLookupRef
           tStoredSearchDeletion.tiStoredSearchId        = tqGetStoredSearchDeletion.tiStoredSearch_ID
           tStoredSearchDeletion.tcAccessLevelLabel      = (if tqGetStoredSearchDeletion.tiUsr_ID = 0
                                                            then if tqGetStoredSearchDeletion.tiRole_ID = 0
                                                                 then vcAccessLevelSystem-TR
                                                                 else vcAccessLevelRole-TR
                                                            else vcAccessLevelUser-TR)
           tStoredSearchDeletion.tiAccessLevel           = (if tqGetStoredSearchDeletion.tiUsr_ID = 0
                                                            then if tqGetStoredSearchDeletion.tiRole_ID = 0
                                                                 then {&CONTROLPROPERTYLAYERTYPE-SYSTEM}
                                                                 else {&CONTROLPROPERTYLAYERTYPE-ROLE}
                                                            else {&CONTROLPROPERTYLAYERTYPE-USER})
           tStoredSearchDeletion.tlCompanyDependent      = (tqGetStoredSearchDeletion.tiCompany_ID <> 0)
           tStoredSearchDeletion.tlSelectedForDeletion   = false.
    if tStoredSearchDeletion.tcStoredSearchName = {&STOREDSEARCH-FACTORY-DEFAULT}
    then tStoredSearchDeletion.tcStoredSearchName = {&STOREDSEARCH-FACTORY-DEFAULT-TR}.
    if tStoredSearchDeletion.tcStoredSearchName = {&STOREDSEARCH-CUSTOMER-DEFAULT}
    then tStoredSearchDeletion.tcStoredSearchName = {&STOREDSEARCH-CUSTOMER-DEFAULT-TR}.

    delete tqGetStoredSearchDeletion.
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 = "BStoredSearch".
create ttContext.
assign ttContext.propertyName = "methodName"
       ttContext.propertyValue = "ApiGetStoredSearchDeletion".
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/bstoredsearch.apigetstoredsearchdeletion.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icName = <parameter value>
       vhParameter::icReference = <parameter value>
       vhParameter::iiAccessLevel = <parameter value>
       vhParameter::iiCurrentRoleID = <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.