Skip to content

Copy attachments (persistent.copyAttachments)


You can copy attachments via scripts in BizzStream in two different methods.

persistent.copyAttachments: When an attachment is copied in a script, a REST call is executed in the background. The script only continues when the REST call returned a response.

persistent.copyAttachmentsLazy: The attachment will be copied after the script has been executed. BizzStream doesn't wait for a response because the script doesn't use the response. With this method you can copy attachments in scripts lazily so that the script execution time will be reduced.


You can use bizzstream.copyAttachments to copy an attachment.

persistent.copyAttachments([
    {
        "source": {sourceOptions},
        "target": {targetOptions}
    }
]);
Source Parameter Type Required Description
ddName String Yes The name of the document definition on which the source document is based. If the value is null, BizzStream will use the name of the document from which the script was started.
_id String No, either the _id or externalId field should be supplied. The id of the source document.
externalId String No, either the _id or externalId field should be supplied. The external ID of the source document.
fieldName String Yes The name of the field from which the attachments should be copied.
lineName String No If the attachment field is part of a line, enter the name of the line here.
lineId String No The ID of the line from which the attachments should be copied.
lineExternalId String No, if the lineName field has a value, either the lineId or lineExternalId should be entered. The external ID of the line from which the attachments should be copied.
FileNames Array No, if neither the field fileNames nor fileIds has been supplied, all attachments are copied. The names of attachments that should be copied.
FileIds Array No, if neither the field fileNames nor fileIds has been supplied, all attachments are copied. The id's of attachments that should be copied.
Target Parameter Type Required Description
ddName String Yes The name of the document definition on which the target document is based. If the value is null, BizzStream will use the name of the document from which the script was started.
_id String No, either the _id or externalId field should be supplied. The id of the target document.
externalId String No, either the _id or externalId field should be supplied. The external ID of the target document.
fieldName String Yes The name of the field to which the attachments should be copied.
lineName String No If the attachment field is part of a line, enter the name of the line here.
lineId String No The ID of the line to which the attachments should be copied.
lineExternalId String No, if the lineName field has a value, either the lineId or lineExternalId should be entered. The external ID of the line to which the attachments should be copied.
clearField Boolean No A boolean value that indicates whether the existing attachments should be removed from the field. If this field is not provided, the field is not cleared.

Example

persistent.copyAttachments([
    {
        "source": {
            "ddName":"menuItem",
            "_id":"3DKKq68tvhpu9bk24",
            "fieldName":"picture",
            "fileIds": ["cmFCNKrx5XE659zP4", "r7LWRi5Rkz8a98Gfm"]
        },
        "target": {
            "ddName":"menuItem",
            "_id":"90f56538c1fb334258952bda",
            "fieldName":"picture",
            "clearField":"true"
        }
    },
    {
        "source": {
            "ddName":"menuItem",
            "_id":"3DKKq68tvhpu9bk24",
            "lineName":"ingredients",
            "fieldName": "preparationInstructions",
            "lineId" : "74240700f347e0b8063b940d",
            "fileNames": ["largescreenshot.png"]
        },
        "target": {
            "ddName":"menuItem",
            "_id":"90f56538c1fb334258952bda",
            "fieldName":"preparationInstructions",
            "lineName": "ingredients",
            "lineExternalId": "12345",
            "clearField":"true"
        }
    }
]);