project BLF > class BDocumentLink > method CopyObjectsDocuments
Description
This method copies all documents from one object to second object
Parameters
| icSourceComponent | input | character | |
| iiSourceObjectId | input | integer | |
| icDestinationComponent | input | character | |
| iiDestinationObjectId | input | integer | |
| oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program1/bdocumentlink.p)
/* ========================================================================= */
/* This method copies all documents from Source object to destination Object */
/* ========================================================================= */
/* Normalize input parameters */
if icSourceComponent = "":U then assign icSourceComponent = ?.
if iiSourceObjectId = 0 then assign iiSourceObjectId = ?.
if icDestinationComponent = "":U then assign icDestinationComponent = ?.
if iiDestinationObjectId = 0 then assign iiDestinationObjectId = ?.
/* Validate input parameters */
if icSourceComponent = ? or
iiSourceObjectId = ? or
icDestinationComponent = ? or
iiDestinationObjectId = ?
then do:
assign vcMessage = #T-4'Not all mandatory parameters are provided.':255(9102)T-4#
vcContext = "icSourceComponent=&1|iiSourceObjectId=&2|icDestinationComponent=&3|iiDestinationObjectId=&4":U
vcContext = substitute(vcContext, icSourceComponent, iiSourceObjectId, icDestinationComponent, iiDestinationObjectId)
vcContext = replace(vcContext, "|":U, chr(2)).
<M-5 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'S':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'BLF-64':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input vcContext (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDocumentLink>
assign oiReturnStatus = -1.
return.
end.
/* Read documents linked to source object, there can be no any document linked to object */
assign vcFreeform =
"for each DocumentLink where ":U +
"DocumentLink.DocumentLinkComponent = '":U + icSourceComponent + "' and ":U +
"DocumentLink.DocumentLinkInternal_ID = ":U + string (iiSourceObjectId).
<M-1 run DataLoad
(input '' (icRowids),
input '' (icPkeys),
input '' (icObjectIds),
input vcFreeform (icFreeform),
input no (ilKeepPrevious),
output viFcReturnSuper (oiReturnStatus)) in BDocumentLink>
if viFcReturnSuper <> 0 and viFcReturnSuper <> -4 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 and viFcReturnSuper <> -4 then return.
/* Create copy of documents linked to source document and point them to destination one */
for each bOrigDocumentLink where
bOrigDocumentLink.DocumentLinkComponent = icSourceComponent and
bOrigDocumentLink.DocumentLinkInternal_ID = iiSourceObjectId
on error undo, throw:
<M-2 run AddDetailLine
(input 'DocumentLink':U (icTable),
input ? (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BDocumentLink>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
buffer-copy bOrigDocumentLink
except DocumentLink_ID
Usr_ID
DocumentLinkComponent
DocumentLinkInternal_ID
tc_ParentRowid
tc_Rowid
tc_Status
to tDocumentLink.
assign tDocumentLink.Usr_ID = viUsrId
tDocumentLink.DocumentLinkComponent = icDestinationComponent
tDocumentLink.DocumentLinkInternal_ID = iiDestinationObjectId.
for each bOrigDocumentStorage where
bOrigDocumentStorage.tc_ParentRowid = bOrigDocumentLink.tc_Rowid
on error undo, throw:
<M-3 run AddDetailLine
(input 'DocumentStorage':U (icTable),
input tDocumentLink.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BDocumentLink>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
buffer-copy bOrigDocumentStorage
except DocumentStorage_ID
DocumentLink_ID
tc_ParentRowid
tc_Rowid
tc_Status
to tDocumentStorage.
end. /* for each bOrigDocumentStorage where */
end. /* for each tDocumentLink where */