Skip to content

Copying Attachments (V1 Versions) (persistent.copyAttachmentsV1 and persistent.copyAttachmentsLazyV1)

You can use persistent.copyAttachmentsV1 or persistent.copyAttachmentsLazyV1 to copy one or more attachments between documents using an older, V1 parameter format.

  • persistent.copyAttachmentsV1: Executes the copy operation immediately when the script runs.
  • persistent.copyAttachmentsLazyV1: Stages the copy operation to be executed later, after the script has finished running.

Both functions take parameters using the V1 structure, which is internally mapped to the structure used by the non-V1 copy functions.

Syntax

persistent.copyAttachmentsV1(copyOperationsArray);
persistent.copyAttachmentsLazyV1(copyOperationsArray);

Parameters

Both functions take a single parameter, which must be an array of objects containing at least one object. Each object in the array specifies one copy operation using the V1 format and both will be explained below per object. First the source object after that the target.

Source Parameter Details

This is the source where the current attachment stands which should be copied.

Parameter Type Required Description
source Object Yes An object defining the source attachment(s) to copy using the V1 format. Contains the following properties:
source.ddName String Yes The document definition name of the source document.
source._id String Required (if externalId is not provided) The ID of the source document.
source.externalId String Required (if _id is not provided) The external ID of the source document.
source.fieldName String Yes The name of the field in the source document containing the attachment(s). (Mapped to valuePath).
source.lineName String Optional If the field is in a line, the name of the line.
source.lineId String Optional (if lineName, either lineId or lineExternalId required) The ID of the source line.
source.lineExternalId String Optional (if lineName, either lineId or lineExternalId required) The external ID of the source line.
source.fileNames Array of Strings Optional List of specific filenames within the source field to copy.
source.fileIds Array of Strings Optional List of specific file IDs within the source field to copy.

Target Parameter Details

Target object where the attachment will be copied to.

Parameter Type Required Description
target Object Yes An object defining the destination for the copied attachment(s) using the V1 format. Contains the following properties:
target.ddName String Yes The document definition name of the target document.
target.._id String Required (if externalId is not provided) The ID of the target document.
target.externalId String Required (if _id is not provided) The external ID of the target document.
target.fieldName String Yes The name of the field in the target document where the attachment should be copied to. (Mapped to valuePath).
target.lineName String Optional If the target field is in a line, the name of the line.
target.lineId String Optional (if lineName, either lineId or lineExternalId required) The ID of the target line.
target.lineExternalId String Optional (if lineName, either lineId or lineExternalId required) The external ID of the target line.

Return value

Does not return anything, undefined.

Example

The following example shows how to copy an attachment from a field in a 'source_document' to a field in a 'target_document' using the V1 parameter format:

// To execute immediately (using V1 format):
persistent.copyAttachmentsV1([
  {
    source: {
      ddName: 'source_docs',
      _id: 'src_doc_1',
      fieldName: 'mainFileField',
      fileNames: ['report.pdf'] // Copy only this specific file
    },
    target: {
      ddName: 'target_docs',
      _id: 'target_doc_1',
      fieldName: 'copiedAttachments'
    }
  }
]);

// To execute lazily after the script (using V1 format):
persistent.copyAttachmentsLazyV1([
  {
    source: {
      ddName: 'source_docs',
      externalId: 'SRC-EXT-001',
      fieldName: 'mainFileField',
      fileIds: [] // In V1, this means copy ALL files in 'mainFileField'
    },
    target: {
      ddName: 'target_docs',
      externalId: 'TARGET-EXT-001',
      fieldName: 'copiedAttachments'
    }
  }
]);