project BLF > class BBusinessComponent > method ApiSynchroniseDefaultActivities

Description

ApiSynchroniseDefaultActivities this method will define some activities as the default activity in case the component had no default activity.


Parameters


olUpdatesDoneoutputlogicalUpdatesDone
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


BLF
method BSystem.ApiSynchronise2


program code (program9/bbusinesscomponent.p)

/* Clear the instance */
<M-1 run ClearData
   (output viFcReturnSuper (oiReturnStatus)) in BBusinessComponent>
   
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.

if oiReturnStatus < 0
then return.

/* Start queries; Read all components and activities */
<Q-2 run BusComponentByLabelCodeID (all) (Read) (NoCache)
   (input ?, (BusComponentID)
    input ?, (BusComponentCode)
    input ?, (BusComponentLabel)
    output dataset tqBusComponentByLabelCodeID) in BBusinessComponent >
    
<Q-3 run BusActivityByLabeslCodesIDs (all) (Read) (NoCache)
   (input ?, (BusComponentID)
    input ?, (BusComponentCode)
    input ?, (BusComponentLabel)
    input ?, (BusActivityID)
    input ?, (BusActivityCode)
    input ?, (BusActivityLabel)
    output dataset tqBusActivityByLabeslCodesIDs) in BBusinessComponent >        
    
/* Go through all components */
for each tqBusComponentByLabelCodeID on error undo, throw:
    /* Skip if this component already has a default activity */
    /* Skip if this component has got no activity            */
    if can-find(first tqBusActivityByLabeslCodesIDs where
                      tqBusActivityByLabeslCodesIDs.tiBusComponent_ID      = tqBusComponentByLabelCodeID.tiBusComponent_ID and
                      tqBusActivityByLabeslCodesIDs.tlBusActivityIsDefault = true) or
       not can-find(first tqBusActivityByLabeslCodesIDs where
                          tqBusActivityByLabeslCodesIDs.tiBusComponent_ID  = tqBusComponentByLabelCodeID.tiBusComponent_ID and
                          tqBusActivityByLabeslCodesIDs.tcBusActivityCode <> "ReturnToSender":U)
    then next.
    
    /* Load the instance */
    <M-4 run DataLoad
       (input  entry (1,tqBusComponentByLabelCodeID.tc_rowid) (icRowids), 
        input  ? (icPkeys), 
        input  ? (icObjectIds), 
        input  '' (icFreeform), 
        input  true (ilKeepPrevious), 
        output viFcReturnSuper (oiReturnStatus)) in BBusinessComponent>
        
    if viFcReturnSuper <> 0
    then assign oiReturnStatus = viFcReturnSuper.
    
    if oiReturnStatus < 0
    then leave.
    
    find tBusComponent where
         tBusComponent.tc_Rowid = entry(1, tqBusComponentByLabelCodeID.tc_rowid)
         no-error.
         
    if not available tBusComponent
    then do:
        assign vcMessage      = trim(subst(#T-9'Unable to load and find the business class based on its row ID (row ID: &1, name: &2) (&3).':255(457)T-9#, entry(1, tqBusComponentByLabelCodeID.tc_rowid), tqBusComponentByLabelCodeID.tcBusComponentCode, "10":U))
               oiReturnStatus = -3.
               
        <M-5 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  entry (1,tqBusComponentByLabelCodeID.tc_rowid) (icRowid), 
            input  'BLF-44':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BBusinessComponent>
            
        leave.
    end.
    
    /* As the instance is loaded now, we can go through all activities and set 1 as the default */
    /* If there is only 1 activity then it is the default                                       */
    /* For Transactional-components the default is Create (2e: Maintain)                        */
    /* For Maintenance-components the default is Modifiy (2e: Maintain)                         */
    find first tBusActivity where
               tBusActivity.tc_ParentRowid   = tBusComponent.tc_Rowid and
               tBusActivity.BusActivityCode <> "ReturnToSender":U
               no-error.

    if not available tBusActivity
    then next.

    find first bBusActivity where
               bBusActivity.tc_ParentRowid   = tBusComponent.tc_Rowid       and
               bBusActivity.BusActivityCode <> tBusActivity.BusActivityCode and
               bBusActivity.BusActivityCode <> "ReturnToSender":U
               no-error.

    if not available bBusActivity
    then do:
        assign olUpdatesDone                     = true
               tBusActivity.BusActivityIsDefault = true
               tBusActivity.tc_Status            = if tBusActivity.tc_Status = "":U
                                                   then "C":U
                                                   else tBusActivity.tc_Status.

        next.
    end.

    if tBusComponent.BusComponentCode = "BDraftInstance":U
    then do:
        find tBusActivity where
             tBusActivity.tc_ParentRowid  = tBusComponent.tc_Rowid and
             tBusActivity.BusActivityCode = "Complete":U
             no-error.

        if available tBusActivity
        then assign olUpdatesDone                     = true
                    tBusActivity.BusActivityIsDefault = true
                    tBusActivity.tc_Status            = if tBusActivity.tc_Status = "":U
                                                        then "C":U
                                                        else tBusActivity.tc_Status.
    end.
    else
    if tBusComponent.BusComponentCategory = "Transactions":U
    then do:
        find tBusActivity where
             tBusActivity.tc_ParentRowid = tBusComponent.tc_Rowid and
             tBusActivity.BusActivityCode begins "CREATE":U
             no-error.

        if not available tBusActivity
        then find tBusActivity where
                  tBusActivity.tc_ParentRowid = tBusComponent.tc_Rowid and
                  tBusActivity.BusActivityCode begins "MAINTAIN":U
                  no-error.

        if available tBusActivity
        then assign olUpdatesDone                     = true
                    tBusActivity.BusActivityIsDefault = true
                    tBusActivity.tc_Status            = if tBusActivity.tc_Status = "":U
                                                        then "C":U
                                                        else tBusActivity.tc_Status.
    end.
    else
    if tBusComponent.BusComponentCategory = "Maintenance":U
    then do:
        find tBusActivity where
             tBusActivity.tc_ParentRowid = tBusComponent.tc_Rowid and
             tBusActivity.BusActivityCode begins "MODIFY":U
             no-error.

        if not available tBusActivity
        then find tBusActivity where
                  tBusActivity.tc_ParentRowid = tBusComponent.tc_Rowid and
                  tBusActivity.BusActivityCode begins "MAINTAIN":U
                  no-error.

        if available tBusActivity
        then assign olUpdatesDone                     = true
                    tBusActivity.BusActivityIsDefault = true
                    tBusActivity.tc_Status            = if tBusActivity.tc_Status = "":U
                                                        then "C":U
                                                        else tBusActivity.tc_Status.
    end.
end.

empty temp-table tqBusComponentByLabelCodeID.
empty temp-table tqBusActivityByLabeslCodesIDs.

if oiReturnStatus < 0
then return.

/* Validate, AdditionalUpdates and Save */
<M-6 run ValidateBC
   (output viFcReturnSuper (oiReturnStatus)) in BBusinessComponent>

if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.

if oiReturnStatus < 0
then return.

<M-7 run AdditionalUpdates
   (output viFcReturnSuper (oiReturnStatus)) in BBusinessComponent>

if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.

if oiReturnStatus < 0
then return.

<M-8 run DataSave
   (output viFcReturnSuper (oiReturnStatus)) in BBusinessComponent>

if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.

if oiReturnStatus < 0
then return.


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 = "BBusinessComponent".
create ttContext.
assign ttContext.propertyName = "methodName"
       ttContext.propertyValue = "ApiSynchroniseDefaultActivities".
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.