How to dynamically attach an attachment to an email

Hi!

I recently discovered this section of the help page:

If I understand correctly, this would allow me to attach files to the email, but based on the instructions I cannot really wrap my head around what I need to add to the script step.

Could someone give an example?

Hi,

Since fileData contains base64 encoded content, it can be extracted using regex and filled into base64Content.

For example:

doo.workflow.attachment.clearAllDynamicAttachments();

const attachments = doo.model.file?.value || [];

const regex = /base64,(.+)$/;

if (attachments.length) {
  for (const attachment of attachments) {
    const base64Content = attachment.fileData?.match(regex);
    attachment.base64Content = base64Content[1] || '';
    doo.workflow.attachment.addDynamicAttachment(attachment);
  }
}

With Regards,

Filip

1 Like

Hi @Filip,

Nothing but respect for you, since you seem to be a one man keeping up the forum :wink::+1::pray:.

On this thread though : is there a setting I am missing or is it possible that this answer has become outdated?

I figured out I can get file data out with using fileId and Tablename parameters, but when I try to access base64 encoded content I always pull a blank. When just console.log-ing fileData (or rather the whole attachment) I don’t seem to ever get anything for fileData result. :thinking:

Not that this is an urgent issue (or even an issue since I just use FileID instead which works just fine) but I am just a curious person and want to make sure I am not missing anything :blush: such as a secret sauce to get directly to the fileData :grin:

Hi @soulex,

we’ll check with our colleagues in the development department to see if we’ve made any recent changes. Yes, fileID should work for sure. I’ll get back to you and post an example with the correct use of base64.

Regards, Filip.

Hi @Filip I have an example of base64 where I create my own base64 :blush: (I create ics object so I can change the title of the event (and other stuff, but that was most important since that is missing in the ical) For this I created a Custom Script I made to encode the created data to Base64 ) . It is accessing the base64 encoded content of an existing attachment I was wondering about.

For @marttiah and anyone looking for an answer to the OP:

The way it works for me to loop through the attachments with ID:

doo.workflow.attachment.clearAllDynamicAttachments();

const attachments = doo.model.file?.value || [];
if (attachments.length) {
  for (const attachment of attachments) {
    doo.workflow.attachment.addDynamicAttachment({fileId: attachment.fileId, fileName: attachment.fileName, tableNameOrId: "TableWhereYourAttachmentIsLocated"});
  }
}