project BLF > class Session > method GetWorkAssistantObjects
Description
Return all work-object in the workflow inbox of current user (excluding work objects belonging to other applications).
Parameters
tWorkAssistant | output | temp-table | Work assistant tasks. |
tWorkAssistantFields | output | temp-table | Which fields to display of objects in the workflow inbox. |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
unused
program code (program5/session.p)
if not vlWorkflowActive
then return.
if vlLoginFailed
then return.
<M-7 run GetIntegerValue (input 'UsrId':U (icName),
output viUsrId (oiValue),
output viFcReturnSuper (oiReturnStatus)) in Session>
<M-2 run GetIntegerValue (input 'CompanyId':U (icName),
output viCompanyId (oiValue),
output viFcReturnSuper (oiReturnStatus)) in Session>
/* =============== */
/* Empty output TT */
/* =============== */
empty temp-table tWorkAssistant.
empty temp-table tWorkAssistantFields.
/* convert code to ID */
<Q-25 run LanguagePrim (all) (Read) (NoCache)
(input current-language, (LngCode)
input 0, (LngID)
output dataset tqLanguagePrim) in BLanguage >
find first tqLanguagePrim where
tqLanguagePrim.tcLngCode = current-language no-error.
if available tqLanguagePrim
then assign viLngId = tqLanguagePrim.tiLng_ID.
/* Query which read all WorkObjects which can be display in WorkBoxAssistance */
<Q-55 run WorkObjectByUsrForWFAll (all) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input viUsrId, (UsrId)
output dataset tqWorkObjectByUsrForWFAll) in BWorkObject >
<Q-56 run WorkObjectByUsrForWFRole (all) (Read) (NoCache) (input viUsrId, (UsrId)
input viCompanyId, (CompanyId)
output dataset tqWorkObjectByUsrForWFRole) in BUserRole >
<Q-54 run WorkObjectByUsrForWFUsr (all) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input viUsrId, (UsrId)
output dataset tqWorkObjectByUsrForWFUsr) in BWorkObject >
Empty Temp-table tWorkAssistantData.
/* copy to indexed table to improve performance */
For Each tqWorkObjectByUsrForWFAll on error undo, throw:
Create tWorkAssistantData.
Buffer-copy tqWorkObjectByUsrForWFAll To tWorkAssistantData.
End.
For Each tqWorkObjectByUsrForWFRole on error undo, throw:
Create tWorkAssistantData.
Buffer-copy tqWorkObjectByUsrForWFRole To tWorkAssistantData.
End.
For Each tqWorkObjectByUsrForWFUsr on error undo, throw:
Create tWorkAssistantData.
Buffer-copy tqWorkObjectByUsrForWFUsr To tWorkAssistantData.
End.
/* =========================================================================================== */
/* Check if the user can execute this activity */
/* - should be linked to one of the roles of the user */
/* - in case the RoleID of the workobject is filled in, the user should be linked to this role */
/* =========================================================================================== */
assign vcActivityToDeleteList = '':U.
empty temp-table tUserBusActivityByUserId.
for each tWorkAssistantData
break by tWorkAssistantData.tiBusActivity_ID on error undo, throw:
if first-of (tWorkAssistantData.tiBusActivity_ID)
then do :
<Q-45 run UserBusActivityByUserId (all) (Read) (NoCache)
(input viUsrId, (UsrId)
input viCompanyId, (CompanyId)
input ?, (RoleId)
input tWorkAssistantData.tiBusComponent_ID, (BusComponentId)
input tWorkAssistantData.tiBusActivity_ID, (BusActivityId)
output dataset tqUserBusActivityByUserId) in BUser >
if not can-find (first tqUserBusActivityByUserId )
then assign vcActivityToDeleteList = vcActivityToDeleteList + string (tWorkAssistantData.tiBusActivity_ID) + ",":U.
else do :
for each tqUserBusActivityByUserId on error undo, throw:
create tUserBusActivityByUserId.
buffer-copy tqUserBusActivityByUserId to tUserBusActivityByUserId.
end.
end.
end.
end.
/*Todo: test on perfomence, maybe it is better to do this check later, I'm not sure. (YanSae)*/
For Each tWorkAssistantData Where
(tWorkAssistantData.tiWorkObjectRole_ID = 0 Or
tWorkAssistantData.tiWorkObjectRole_ID = ?) And
tWorkAssistantData.tiUsr_ID <> 0 And
tWorkAssistantData.tiUsr_ID <> ? And
tWorkAssistantData.tiUsr_ID <> viUsrId:
Delete tWorkAssistantData.
End.
for each tWorkAssistantData where
tWorkAssistantData.tiWorkObjectRole_ID <> 0 and
tWorkAssistantData.tiWorkObjectRole_ID <> ?:
if not can-find (first tUserBusActivityByUserId where
tUserBusActivityByUserId.tiRole_ID = tWorkAssistantData.tiWorkObjectRole_ID and
tUserBusActivityByUserId.tiBusActivity_ID = tWorkAssistantData.tiBusActivity_ID)
then delete tWorkAssistantData.
end.
/* Delete all WorkAssistantData for which the user has no rights */
if vcActivityToDeleteList <> '':U
then do viTempCnt = 1 to num-entries (vcActivityToDeleteList,",":U) - 1 :
for each tWorkAssistantData where
tWorkAssistantData.tiBusActivity_ID = integer (entry (viTempCnt,vcActivityToDeleteList ,",":U)) :
delete tWorkAssistantData.
end.
end.
for each tUserBusActivityByUserId break by tUserBusActivityByUserId.tiBusActivity_ID on error undo, throw:
if not first-of (tUserBusActivityByUserId.tiBusActivity_ID)
then next.
for each tWorkAssistantData where
tWorkAssistantData.tiBusActivity_ID = tUserBusActivityByUserId.tiBusActivity_ID
by tWorkAssistantData.ttLastModifiedDate
by tWorkAssistantData.tiLastModifiedTime on error undo, throw:
/* ================================================================= */
/* Avoid duplicates */
/* ================================================================= */
if can-find (first tWorkAssistant where
tWorkAssistant.tiInternalObjectId = abs(tWorkAssistantData.tiWorkObjectInternal_ID))
then next.
/* ================================================================= */
/* For draft instances, check if the draft is not already in use */
/* ================================================================= */
if tWorkAssistantData.tiWorkObjectInternal_ID < 0 and
tWorkAssistantData.tiInstance_ID <> ? and
tWorkAssistantData.tiInstance_ID <> 0
then next.
/* ======================= */
/* Create output TT-record */
/* ======================= */
create tWorkAssistant.
assign viWOSequence = viWOSequence + 1
tWorkAssistant.tiWOSequence = viWOSequence
tWorkAssistant.tiRole_ID = tUserBusActivityByUserId.tiRole_ID
tWorkAssistant.tcRoleDescription = tUserBusActivityByUserId.tcRoleDescription
tWorkAssistant.tcActivityCode = tUserBusActivityByUserId.tcBusActivityCode
tWorkAssistant.tcBusinessComponentName = tUserBusActivityByUserId.tcBusComponentCode
tWorkAssistant.tiInternalObjectId = abs(tWorkAssistantData.tiWorkObjectInternal_ID)
tWorkAssistant.tiDraftInstanceId = (if tWorkAssistantData.tiWorkObjectInternal_ID < 0
then - tWorkAssistantData.tiWorkObjectInternal_ID
else 0)
tWorkAssistant.tcWorkQueueDescription = #T-49'Default':10(4985)T-49#.
find first tWorkInboxCache where
tWorkInboxCache.tcBusinessComponentName = tWorkAssistant.tcBusinessComponentName and
tWorkInboxCache.tcActivityCode = tWorkAssistant.tcActivityCode
no-error.
if not available tWorkInboxCache
then do:
find first tBusinessActivities where
tBusinessActivities.tcClassName = tWorkAssistant.tcBusinessComponentName and
tBusinessActivities.tcName = tWorkAssistant.tcActivityCode no-error.
if not available tBusinessActivities
then do:
empty temp-table tSessionBusinessComponents .
empty temp-table tBusinessActivities .
run appinfo/naviginfo.p
(input vhFcSuper,
input table tSessionBusinessComponents by-reference,
input table tBusinessActivities by-reference).
find first tBusinessActivities where
tBusinessActivities.tcClassName = tWorkAssistant.tcBusinessComponentName and
tBusinessActivities.tcName = tWorkAssistant.tcActivityCode no-error.
end.
create tWorkInboxCache.
assign tWorkInboxCache.tcBusinessComponentName = tWorkAssistant.tcBusinessComponentName
tWorkInboxCache.tcActivityCode = tWorkAssistant.tcActivityCode
tWorkInboxCache.tcActivityLabel = (if available tBusinessActivities
then tBusinessActivities.tcLabel
else tWorkAssistant.tcActivityCode).
find first tSessionBusinessComponents where
tSessionBusinessComponents.tcName = tWorkAssistant.tcBusinessComponentName no-error.
if available tSessionBusinessComponents
then assign tWorkInboxCache.tcBusinessComponentLabel = tSessionBusinessComponents.tcLabel.
end.
assign tWorkAssistant.tcActivityLabel = tWorkInboxCache.tcActivityLabel
tWorkAssistant.tcBusinessComponentLabel = tWorkInboxCache.tcBusinessComponentLabel
tWorkAssistant.tcBusinessAreaLabel = tWorkInboxCache.tcBusinessAreaLabel.
/* =========================================================== */
/* Run query that returns the fields that need to be displayed */
/* =========================================================== */
if not can-find (first tqWorkQueueFieldsByRoleCompAct where
tqWorkQueueFieldsByRoleCompAct.tiRole_ID = tUserBusActivityByUserId.tiRole_ID and
tqWorkQueueFieldsByRoleCompAct.tcBusComponentCode = tUserBusActivityByUserId.tcBusComponentCode and
tqWorkQueueFieldsByRoleCompAct.tcBusActivityCode = tUserBusActivityByUserId.tcBusActivityCode)
then do:
<Q-21 run WorkQueueFieldsByRoleCompAct (all) (Read) (Cache)
(input tUserBusActivityByUserId.tcBusActivityCode, (BusAcitivityCode)
input tUserBusActivityByUserId.tcBusComponentCode, (BusComponentCode)
input tUserBusActivityByUserId.tiRole_ID, (RoleID)
output dataset tqWorkQueueFieldsByRoleCompAct) in BRole >
end. /* if not available tqWorkQueueFieldsByRoleCompAct */
find first tqWorkQueueFieldsByRoleCompAct no-error.
if available tqWorkQueueFieldsByRoleCompAct
then if viLngID = 0
then assign tWorkAssistant.tcWorkQueueDescription = tqWorkQueueFieldsByRoleCompAct.tcWorkQueueDescription.
else do:
<Q-26 run TranslationByIDLngParent (all) (Read) (NoCache)
(input viLngID, (LngID)
input tqWorkQueueFieldsByRoleCompAct.tiWorkQueue_ID, (ParentID)
input 0, (TranslationID)
output dataset tqTranslationByIDLngParent) in BTranslation >
find first tqTranslationByIDLngParent no-error.
if available tqTranslationByIDLngParent
then tWorkAssistant.tcWorkQueueDescription = tqTranslationByIDLngParent.tcTranslationStringText.
else tWorkAssistant.tcWorkQueueDescription = tqWorkQueueFieldsByRoleCompAct.tcWorkQueueDescription.
end.
if tWorkAssistantData.tiWorkObjectInternal_ID < 0
then do:
create tWorkAssistantFields.
assign tWorkAssistantFields.tiInternalObjectId = tWorkAssistant.tiInternalObjectId
tWorkAssistantFields.tcBusinessFieldLabel = #T-50'Document':20(508)T-50#
tWorkAssistantFields.tcBusinessFieldName = "Document":U
tWorkAssistantFields.tcBusinessFieldValue = tWorkAssistantData.tcWorkObjectInstruction.
next.
end.
/* ================================================================= */
/* Start the business component of the work object */
/* ================================================================= */
if vcBusinessComponent <> tWorkAssistant.tcBusinessComponentName
then do:
if vcBusinessComponent <> ""
then do:
<M-13 run BusinessClassActions
(input vcBusinessComponent (icClassShortname),
input 'CLOSE+STOP':U (icAction),
input no (ilSubtransaction),
input-output viOpenC (biClassOpenCount),
input-output vhdatabase1Inst (bhClassInstanceHandle),
input-output vidatabase1ID (biClassInstanceId),
input '' (icDraftReference),
output viFcReturnSuper (oiReturnStatus)) in Session>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
end.
assign vcBusinessComponent = lc (tWorkAssistant.tcBusinessComponentName).
<M-14 run BusinessClassActions
(input vcBusinessComponent (icClassShortname),
input 'START+OPEN':U (icAction),
input no (ilSubtransaction),
input-output viOpenC (biClassOpenCount),
input-output vhdatabase1Inst (bhClassInstanceHandle),
input-output vidatabase1ID (biClassInstanceId),
input '' (icDraftReference),
output viFcReturnSuper (oiReturnStatus)) in Session>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
end.
if can-find (first tqWorkQueueFieldsByRoleCompAct)
then do:
/* ================================================================= */
/* Load the work object in the business component */
/* and lookup the values to display of the object. */
/* ================================================================= */
<M-39 run DataLoad (input '' (icRowids),
input '' (icPkeys),
input string(tWorkAssistant.tiInternalObjectId) (icObjectIds),
input '' (icFreeform),
input no (ilKeepPrevious),
output viFcReturnSuper (oiReturnStatus)) in database>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
/* not found = database corruption */
if viFcReturnSuper = -4
then do:
assign vhFcComponent = ?
oiReturnStatus = -25.
<M-40 run CreateCorruption
(input 'workobject':U (icTableName),
input 'ID=':U + string (tWorkAssistantData.tiWorkObject_ID) (icKey),
input 'Invalid object reference (':U + tWorkAssistant.tcBusinessComponentName + '/':U + string(tWorkAssistant.tiInternalObjectId) + ')':U (icDescription),
input ? (ilSkipMessage),
output viFcReturnSuper (oiReturnStatus)) in BCorrLog>
end.
<M-41 run BusinessClassActions
(input vcBusinessComponent (icClassShortname),
input 'CLOSE+STOP':U (icAction),
input no (ilSubtransaction),
input-output viOpenC (biClassOpenCount),
input-output vhdatabase1Inst (bhClassInstanceHandle),
input-output vidatabase1ID (biClassInstanceId),
input '' (icDraftReference),
output viFcReturnSuper (oiReturnStatus)) in Session>
return.
end.
if search ("appinfo/":U + vcBusinessComponent + "_label.r":U) <> ?
or search ("appinfo/":U + vcBusinessComponent + "_label.p":U) <> ?
then for each tqWorkQueueFieldsByRoleCompAct on error undo, throw:
run value ("appinfo/":U + lc(vcBusinessComponent) + "_label.p":U)
(input vhFcSuper,
input tqWorkQueueFieldsByRoleCompAct.tcBusinessField,
output vcFieldLabel).
if vcFieldLabel = "" then next.
create tWorkAssistantFields.
assign tWorkAssistantFields.tiInternalObjectId = tWorkAssistant.tiInternalObjectId
tWorkAssistantFields.tcBusinessFieldLabel = vcFieldLabel
tWorkAssistantFields.tcBusinessFieldName = tqWorkQueueFieldsByRoleCompAct.tcBusinessField
vcTable = "t_o":U + substring(entry(1,tqWorkQueueFieldsByRoleCompAct.tcBusinessField,".":U),2,-1,"CHARACTER":U).
<M-42 run ReadTable
(input vcTable (icTableName),
input 'for each ':U + vcTable (icQuery),
input entry (2,tBusinessFields.tcFcFieldName,'.':U) (icFieldNames),
input yes (ilConvertToDisplayFormat),
output tWorkAssistantFields.tcBusinessFieldValue (ocFieldValues),
output viFcReturnSuper (oiReturnStatus)) in database>
end.
end.
else do:
/* ================================================================= */
/* Load the work object in the business component */
/* and make a standard description, based on alternate key. */
/* (or primary key if no alternate key is available) */
/* ================================================================= */
assign vcPKValue = ""
vcDummyChar = ""
vcAKValues = "".
<M-32 run ApiGetIdentification (input-output vcPKValue (bcPrimaryKey),
input-output vcAKValues (bcAlternateKey),
input-output vcDummyChar (bcRowid),
input-output tWorkAssistant.tiInternalObjectId (biObjectId),
output vcDummyChar (ocObjectStatusValues),
output vcDummyChar (ocObjectStatusFieldNames),
output vcPKName (ocPrimaryKeyFieldNames),
output vcAKNames (ocAlternateKeyFieldNames),
output vcAKLabels (ocAlternateKeyFieldLabels),
output viFcReturnSuper (oiReturnStatus)) in database>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
/* not found = database corruption */
if viFcReturnSuper = -4
then do:
assign vhFcComponent = ?
oiReturnStatus = -25.
<M-33 run CreateCorruption
(input 'workobject':U (icTableName),
input 'ID=':U + string (tWorkAssistantData.tiWorkObject_ID) (icKey),
input 'Invalid object reference (':U + tWorkAssistant.tcBusinessComponentName + '/':U + string(tWorkAssistant.tiInternalObjectId) + ')':U (icDescription),
input ? (ilSkipMessage),
output viFcReturnSuper (oiReturnStatus)) in BCorrLog>
end.
<M-34 run BusinessClassActions
(input vcBusinessComponent (icClassShortname),
input 'CLOSE+STOP':U (icAction),
input no (ilSubtransaction),
input-output viOpenC (biClassOpenCount),
input-output vhdatabase1Inst (bhClassInstanceHandle),
input-output vidatabase1ID (biClassInstanceId),
input '' (icDraftReference),
output viFcReturnSuper (oiReturnStatus)) in Session>
return.
end.
if vcAKNames = ""
then do:
create tWorkAssistantFields.
assign tWorkAssistantFields.tiInternalObjectId = tWorkAssistant.tiInternalObjectId
tWorkAssistantFields.tcBusinessFieldLabel = ""
tWorkAssistantFields.tcBusinessFieldName = vcPKName
tWorkAssistantFields.tcBusinessFieldValue = vcPKValue.
end.
else do viFcCount2 = 1 to num-entries(vcAKNames):
create tWorkAssistantFields.
assign tWorkAssistantFields.tiInternalObjectId = tWorkAssistant.tiInternalObjectId
tWorkAssistantFields.tcBusinessFieldLabel = entry(viFcCount2,vcAKLabels,chr(2))
tWorkAssistantFields.tcBusinessFieldName = entry(viFcCount2,vcAKNames)
tWorkAssistantFields.tcBusinessFieldValue = entry(viFcCount2,vcAKValues,chr(2)).
end.
end.
end. /* for each tWorkAssistantData */
end. /* tUserBusActivityByUserId */
finally:
if vcBusinessComponent <> ""
then do:
<M-17 run BusinessClassActions
(input vcBusinessComponent (icClassShortname),
input 'CLOSE+STOP':U (icAction),
input no (ilSubtransaction),
input-output viOpenC (biClassOpenCount),
input-output vhdatabase1Inst (bhClassInstanceHandle),
input-output vidatabase1ID (biClassInstanceId),
input '' (icDraftReference),
output viFcReturnSuper (oiReturnStatus)) in Session>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
end.
/* clean-up */
empty temp-table tSessionBusinessComponents.
empty temp-table tBusinessActivities.
Empty Temp-table tUserBusActivityByUserId.
Empty Temp-table tWorkAssistantData.
end finally.
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 = "Session".
create ttContext.
assign ttContext.propertyName = "methodName"
ttContext.propertyValue = "GetWorkAssistantObjects".
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.