project BLF > class Database Component > method UpdateWorkobject
Description
When updating a database object that is registered in workflow, lookup the corresponding work object and update the status of it (either return the work object to sender or delete it).
Parameters
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
BLF
program code (program1/database.p)
if oiReturnStatus = 0
then oiReturnStatus = -98.
/*check if there is at least one record found in WorkObject fot the current component.
If not, leave the method. */
<Q-12 assign vlFcQueryRecordsAvailable = BusComponentForWorkObject (NoCache)
(input vcFcComponentName, (BusComponentCode)
input ?, (CompanyId)) in BBusinessComponent >
if vlFcQueryRecordsAvailable = false
then do:
assign oiReturnStatus = 0.
return.
end.
if viTransactionID = 0
then assign vcObjectName = "".
else do:
<I-1 {bFcOpenInstance
&CLASS = "transaction"}>
<M-2 run GetInstances (input 'BWorkObject':U (icClass),
output vcObjectName (ocInstances),
output viLocalReturn (oiReturnStatus)) in Transaction>
<I-3 {bFcCloseInstance
&CLASS = "transaction"}>
if viLocalReturn <> 0
then oiReturnStatus = viLocalReturn.
if viLocalReturn < 0
then return.
end.
if vcObjectName = ""
then do:
<Q-4 assign vlFcQueryRecordsAvailable = LookupWorkObject (NoCache) (input 0, (CompanyId)
input vcFcComponentName, (BusComponentCode)
input - viFcCurrentInstanceId, (InternalObjectId)) in BWorkObject >
if vlFcQueryRecordsAvailable
then assign vcKeys = ",":U + string(- viFcCurrentInstanceId).
else do:
<M-5 run DataDescription
(input '' (icRowids),
input '' (icPkey),
input '' (icObjectIds),
input no (ilAllTables),
output viFcReturnSuper (oiReturnStatus)) in database>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
find first tFcDynRel where
tFcDynRel.tcFcFrom = "" no-error.
if available tFcDynRel
then do:
<M-6 run GetKeyFields (input-output tFcDynRel.tcFcTo (bcTableName),
output vcDummy (ocPrimaryKey),
output vcDummy (ocAlternateKey),
output vcObjectName (ocObjectID),
output vcDummy (ocObjectStatus),
output viFcReturnSuper (oiReturnStatus)) in database>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
if vcObjectName <> ""
then do:
assign vcTable = tFcDynRel.tcFcTo
vhBuffer = tFcDynRel.thFcBuffer
vhField = vhBuffer:buffer-field (vcObjectName).
create query vhQuery in widget-pool "non-persistent".
vhQuery:forward-only = yes.
vhQuery:set-buffers(vhBuffer).
vhQuery:query-prepare("for each t_o":U + vcTable +
" where t_o":U + vcTable + ".tc_Status <> 'D'":U).
vhQuery:query-open().
vhQuery:get-first().
do while not vhQuery:query-off-end:
viObjectId = vhField:buffer-value.
<Q-7 assign vlFcQueryRecordsAvailable = LookupWorkObject (NoCache) (input 0, (CompanyId)
input vcFcComponentName, (BusComponentCode)
input viObjectId, (InternalObjectId)) in BWorkObject >
if vlFcQueryRecordsAvailable
then assign vcKeys = vcKeys + ",":U + string(viObjectId).
vhQuery:get-next().
end.
vhQuery:query-close().
delete object vhQuery.
end.
end.
end.
if vcKeys <> ""
then do:
<I-8 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "true"
&CLASS = "BWorkObject"}>
<M-9 run UpdateWorkobjectStatus (input vcFcComponentName (icBusComponentCode),
input substring(vcKeys,2,-1,'CHARACTER':U) (icObjectIdentifiers),
input vcActivityCode (icBusActivityCode),
output viFcReturnSuper (oiReturnStatus)) in BWorkObject>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
<I-10 {bFcCloseAndStopInstance
&CLASS = "BWorkObject"}>
return.
end.
/* ========================================================================================================= */
/* Normally we would here close BWorkObject but we will not do it for performance */
/* reasons as this way the Commit of the transaction does not have to re-open the instance to commit it. */
/* And in all other scenario's the instance of the class ill be closed by the de-activiate procedure of the */
/* appserver that is executed after each call to the appserver */
/* ========================================================================================================= */
end.
end.
if oiReturnStatus = -98
then oiReturnStatus = 0.