project BLF > class BWorkObject > method PostSave
Description
Actions to take after writing current instance to the database, and before final commit of the transaction.
Use the field tc_status to test the status of the updated records:
'' = unchanged
'N' = new
'C' = changed
'D' = deleted
Parameters
oiReturnStatus | output | integer | |
Internal usage
unused
program code (program/bworkobject.p)
<ANCESTOR-CODE>
for each tWorkObject where
tWorkObject.tc_Status = "N" or
tWorkObject.tc_Status = "C" on error undo, throw:
If tWorkObject.WorkObjectIsSendMail
Then Do:
/* Send mails to all members of the role */
Assign vcToMailAddress = "":U.
If tWorkObject.Role_ID <> 0 And
tWorkObject.Role_ID <> ?
Then Do:
<Q-23 run UserByRoleId (all) (Read) (NoCache)
(input tWorkObject.Role_ID, (RoleId)
input True, (UsrIsActive)
input viCompanyId, (CompanyId)
output dataset tqUserByRoleId) in BUser>
For Each tqUserByRoleId:
If vcToMailAddress = "":U
Then Assign vcToMailAddress = tqUserByRoleId.tcUsrMailAddress.
Else Assign vcToMailAddress = vcToMailAddress + "|":U + tqUserByRoleId.tcUsrMailAddress.
End.
End.
/* Send mail to tWorkObject.Usr_ID */
If tWorkObject.Usr_ID <> 0 And
tWorkObject.Usr_ID <> ?
Then Do:
<Q-79 run UserById (all) (Read) (NoCache)
(input tWorkObject.Usr_ID, (UsrId)
output dataset tqUserById) in BUser>
Find First tqUserById no-error.
If Available tqUserById
Then If vcToMailAddress = "":U
Then Assign vcToMailAddress = tqUserById.tcUsrMailAddress.
Else Assign vcToMailAddress = vcToMailAddress + "|":U + tqUserById.tcUsrMailAddress.
End.
Assign vcFromMailAddress = "":U.
If tWorkObject.CreatorUsr_ID <> 0 And
tWorkObject.CreatorUsr_ID <> ?
Then Do:
<Q-48 run UserById (all) (Read) (NoCache)
(input tWorkObject.CreatorUsr_ID, (UsrId)
output dataset tqUserById) in BUser>
Find First tqUserById no-error.
If Available tqUserById
Then Assign vcFromMailAddress = tqUserById.tcUsrMailAddress.
End.
If /*vcFromMailAddress = '':U Or*/
vcToMailAddress = '':U
Then Next.
<Q-68 run BusActivityByLabeslCodesIDs (all) (Read) (NoCache)
(input ?, (BusComponentID)
input ?, (BusComponentCode)
input ?, (BusComponentLabel)
input tWorkObject.BusActivity_ID, (BusActivityID)
input ?, (BusActivityCode)
input ?, (BusActivityLabel)
output dataset tqBusActivityByLabeslCodesIDs) in BBusinessComponent>
find first tqBusActivityByLabeslCodesIDs where
tqBusActivityByLabeslCodesIDs.tiBusActivity_ID = tWorkObject.BusActivity_ID no-error.
Assign
vcMailSubject = Trim(#T-51'Please check your application work inbox.':255(6515)T-51#)
vcMailBody = Trim(#T-38'Please check your application work inbox.':255(6515)T-38#) + Chr(10) +
(if available tqBusActivityByLabeslCodesIDs
then tqBusActivityByLabeslCodesIDs.tcBusComponentLabel
else tWorkObject.tcBusComponentCode) + " ":U +
(if available tqBusActivityByLabeslCodesIDs
then tqBusActivityByLabeslCodesIDs.tcBusActivityLabel
else tWorkObject.tcBusActivityCode) + Chr(10) +
tWorkObject.WorkObjectInstruction.
<I-54 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "False"
&CLASS = "Mail"}>
<M-90 run Send
(input vcFromMailAddress (icFrom),
input vcToMailAddress (icTo),
input vcMailSubject (icSubject),
input vcMailBody (icBody),
output viMailReturnStatus (oiReturnStatus)) in Mail>
<I-49 {bFcCloseAndStopInstance
&CLASS = "Mail"}>
End. /*If tWorkObject.WorkObjectIsSendMail*/
/* ================================================================= */
/* Lookup object reference if not already provided. */
/* ================================================================= */
if tWorkObject.tcWorkObjectInternalRef = ""
then do:
if tWorkObject.WorkObjectInternal_ID < 0
then do:
assign vibbusinessComponent7ID = - tWorkObject.WorkObjectInternal_ID
viDummy = 0
vcRowid = ""
vcPK = ""
vcAK = "".
<M-18 run BusinessClassActions
(input tWorkObject.tcBusComponentCode (icClassShortname),
input 'OPEN' (icAction),
input no (ilSubtransaction),
input-output viBBusinessComponent7OC (biClassOpenCount),
input-output vhBBusinessComponent7Inst (bhClassInstanceHandle),
input-output viBBusinessComponent7ID (biClassInstanceId),
input '' (icDraftReference),
output viFcReturnSuper (oiReturnStatus)) in BWorkObject>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
<M-19 run ApiGetIdentification
(input-output vcPK (bcPrimaryKey),
input-output vcAK (bcAlternateKey),
input-output vcRowid (bcRowid),
input-output viDummy (biObjectId),
output vcDummy (ocObjectStatusValues),
output vcDummy (ocObjectStatusFieldNames),
output vcDummy (ocPrimaryKeyFieldNames),
output vcDummy (ocAlternateKeyFieldNames),
output vcDummy (ocAlternateKeyFieldLabels),
output viFcReturnSuper (oiReturnStatus)) in BBusinessComponent>
<M-20 run BusinessClassActions
(input tWorkObject.tcBusComponentCode (icClassShortname),
input 'CLOSE' (icAction),
input no (ilSubtransaction),
input-output viBBusinessComponent7OC (biClassOpenCount),
input-output vhBBusinessComponent7Inst (bhClassInstanceHandle),
input-output viBBusinessComponent7ID (biClassInstanceId),
input '' (icDraftReference),
output viFcReturnSuper (oiReturnStatus)) in BWorkObject>
end.
else do:
assign viBBusinessComponent7ID = 0.
if viTransactionID <> 0
then do:
<I-12 {bFcOpenInstance
&CLASS = "Transaction"}>
<M-13 run GetInstances
(input tWorkObject.tcBusComponentCode (icClass),
output vcIns (ocInstances),
output viFcReturnSuper (oiReturnStatus)) in Transaction>
<I-14 {bFcCloseInstance
&CLASS = "Transaction"}>
assign viBBusinessComponent7ID = integer(entry(2, vcIns)) no-error.
end.
assign vlStart = vibbusinessComponent7ID = 0
vcRowid = ""
vcPK = ""
vcAK = "".
<M-15 run BusinessClassActions
(input tWorkObject.tcBusComponentCode (icClassShortname),
input if vlStart then 'START+OPEN' else 'OPEN' (icAction),
input no (ilSubtransaction),
input-output viBBusinessComponent7OC (biClassOpenCount),
input-output vhBBusinessComponent7Inst (bhClassInstanceHandle),
input-output viBBusinessComponent7ID (biClassInstanceId),
input '' (icDraftReference),
output viFcReturnSuper (oiReturnStatus)) in BWorkObject>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
<M-16 run ApiGetIdentification
(input-output vcPK (bcPrimaryKey),
input-output vcAK (bcAlternateKey),
input-output vcRowid (bcRowid),
input-output tWorkObject.WorkObjectInternal_ID (biObjectId),
output vcDummy (ocObjectStatusValues),
output vcDummy (ocObjectStatusFieldNames),
output vcDummy (ocPrimaryKeyFieldNames),
output vcDummy (ocAlternateKeyFieldNames),
output vcDummy (ocAlternateKeyFieldLabels),
output viFcReturnSuper (oiReturnStatus)) in BBusinessComponent>
<M-17 run BusinessClassActions
(input tWorkObject.tcBusComponentCode (icClassShortname),
input if vlStart then 'CLOSE+STOP' else 'CLOSE' (icAction),
input no (ilSubtransaction),
input-output viBBusinessComponent7OC (biClassOpenCount),
input-output vhBBusinessComponent7Inst (bhClassInstanceHandle),
input-output viBBusinessComponent7ID (biClassInstanceId),
input '' (icDraftReference),
output viFcReturnSuper (oiReturnStatus)) in BWorkObject>
end.
assign tWorkObject.tcWorkObjectInternalRef = if vcAK = ""
then vcPK
else replace(vcAK, chr(2), "/").
end.
/* ================================================================= */
/* Send the object to work inbox. */
/* ================================================================= */
if tWorkObject.tc_Status = "N"
then vlFcOk = yes.
else do:
find t_iWorkObject where t_iWorkObject.tc_Rowid = tWorkObject.tc_Rowid no-error.
if available t_iWorkObject
then vlFcOk = (t_iWorkObject.WorkObjectIsReturnToSender = yes and
tWorkObject.WorkObjectIsReturnToSender = no).
else vlFcOk = no.
end.
if vlFcOk
then do:
/* Subject does not use codes but labels */
assign vcSubject = tWorkObject.tcBusComponentCode + ".":U + tWorkObject.tcBusActivityCode.
if tWorkObject.BusActivity_ID = 0
then do:
if tWorkObject.BusComponent_ID <> 0
then do:
<Q-10 run BusComponentPrim (all) (Read) (NoCache)
(input tWorkObject.BusComponent_ID, (BusComponentID)
input '', (BusComponentCode)
output dataset tqBusComponentPrim) in BBusinessComponent >
find first tqBusComponentPrim where
tqBusComponentPrim.tiBusComponent_ID = tWorkObject.BusComponent_ID
no-error.
if available tqBusComponentPrim
then assign vcSubject = tqBusComponentPrim.tcBusComponentLabel.
end.
end.
else do:
<Q-11 run BusActivityPrim (all) (Read) (NoCache)
(input tWorkObject.BusActivity_ID, (BusActivityID)
input '', (BusActivityCode)
input '', (BusComponentCode)
output dataset tqBusActivityPrim) in BBusinessComponent >
find first tqBusActivityPrim where
tqBusActivityPrim.tiBusActivity_ID = tWorkObject.BusActivity_ID
no-error.
if available tqBusActivityPrim
then assign vcSubject = tqBusActivityPrim.tcBusComponentLabel + "." + tqBusActivityPrim.tcBusActivityLabel.
end.
/* Create a message in the queue that is used by AppShell for the inbox */
<I-1 {bFcStartAndOpenInstance
&CLASS = "PWorkInbox"}>
assign vcFrom = tWorkObject.tcCreatorUsrLogin
vcSubject = vcSubject + " (" + tWorkObject.tcWorkObjectInternalRef + ")"
vcContent = tWorkObject.WorkObjectInstruction + "<BR>" +
"<a href=~"qadsh://menu/invoke?menuitem-alias=":U +
tWorkObject.tcBusComponentCode + ".":U + tWorkObject.tcBusActivityCode +
"&OpenFromInbox=true":U +
"&InternalObjectId=":U + string(abs(tWorkObject.WorkObjectInternal_ID)) +
(if tWorkObject.WorkObjectInternal_ID < 0
then "&DraftInstanceId=":U + string ( - tWorkObject.WorkObjectInternal_ID)
else "") +
"~">" + vcSubject + "</a>"
vcGuid = tWorkObject.WorkObjectExternalRef.
/* Currently the vcSubject is filled in statically. In the original implementation, this was
configurable by the end-user. Check session.GetWorkAssistantObjects for this implementation. */
if tWorkObject.Role_ID = 0 or
tWorkObject.Role_ID = ?
then if tWorkObject.tc_Status = "C"
and tWorkObject.tcBusActivityCode = "ReturnToSender"
then assign vcTo = tWorkObject.tcCreatorUsrLogin
vcFrom = vcUserLogin
vcContent = tWorkObject.WorkObjectInstruction + "<BR>" +
"<a href=~"qadsh://menu/invoke?menuitem-alias=":U +
tWorkObject.tcBusComponentCode + ".View":U +
"&OpenFromInbox=true":U +
"&InternalObjectId=":U + string(abs(tWorkObject.WorkObjectInternal_ID)) +
(if tWorkObject.WorkObjectInternal_ID < 0
then "&DraftInstanceId=":U + string ( - tWorkObject.WorkObjectInternal_ID)
else "") +
"~">" + vcSubject + "</a>".
else assign vcTo = tWorkObject.tcTo.
else do:
/* Derive the "to" from the role to which the workobject is sent. */
<Q-8 run UserRoleByRoleId (all) (Read) (NoCache)
(input tWorkObject.Role_ID, (RoleId)
output dataset tqUserRoleByRoleId) in BUserRole >
for each tqUserRoleByRoleId where
tqUserRoleByRoleId.tiRole_ID = tWorkObject.Role_ID:
assign vcTo = vcTo + ",":U + tqUserRoleByRoleId.tcUsrLogin.
end.
assign vcTo = substring(vcTo, 2, -1, "CHARACTER").
end.
vcContent = replace(vcContent,chr(10),"<BR>").
<M-4 run CreateMessage
(input vcFrom (icFrom),
input vcTo (icTo),
input vcCc (icCc),
input vcBcc (icBcc),
input vcSubject (icSubject),
input vcContent (icContent),
input vcGuid (icGuid),
input 'text/plain':U (icContentType),
output viFcReturnSuper (oiReturnStatus)) in PWorkInbox>
<I-3 {bFcCloseAndStopInstance
&CLASS = "PWorkInbox"}>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
end.
end.
/* ================================================================= */
/* Delete the corresponding message from the queue that is used by */
/* AppShell for the inbox. */
/* ================================================================= */
for each tWorkObject where tWorkObject.tc_Status = "D" on error undo, throw:
<I-5 {bFcStartAndOpenInstance
&CLASS = "PWorkInbox"}>
<M-9 run DeleteMessage
(input tWorkObject.WorkObjectExternalRef (icMessageGuid),
output viFcReturnSuper (oiReturnStatus)) in PWorkInbox>
<I-7 {bFcCloseAndStopInstance
&CLASS = "PWorkInbox"}>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
end.