Dynamic attachments for email templates

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RaptorBlue
    Junior Member
    • Oct 2022
    • 10

    Dynamic attachments for email templates

    Hi,

    I've been running EspoCRM for a while now and I am very happy with it. One thing would improve my work flow tremendously though:
    The possibility to add attachments based on variables to email templates.

    The use case is as follows:
    I have data sheets for my products as documents (i.e. DataSheet-X12345.pdf) whereas X12345 is the product id. Currently when using a template I manually have to add the attachment but defining this in the template like "Add attachment: DataSheet-{{ product.id }}.pdf" would be great.

    Is this possible to implement in future versions?

    Thanks a lot!
    R.
  • lazovic
    Super Moderator
    • Jan 2022
    • 809

    #2
    Hi RaptorBlue,

    Could you please send a screenshot of your Workflow so that we can conduct a detailed analysis and adjust it in the way you need?

    I can say right away that you will need to use Execute Formula Script Action to create an email, add the necessary attachment to it and send this email.

    Comment

    • RaptorBlue
      Junior Member
      • Oct 2022
      • 10

      #3
      Hi lazovic,

      Thank you for your reply. Attached you can find a screenshot of my mail template with the placeholders (i.e. {Product.id}). When sending an email with this template the variables are replaced as intended but I have to manually click on the document icon and add PDF from the list of documents.
      My wish is to define it a *dynamic* attachment in the template telling the system not only to replace the variables but also automatically add the document. (Add: Datasheet-{Product.id}.pdf from Documents)

      I hope it's clear what I am trying to do. Please let me know when I can help.

      Best regards,
      RaptorBlue

      Comment

      • lazovic
        Super Moderator
        • Jan 2022
        • 809

        #4
        RaptorBlue,

        You can do this by automating the email sending process with Workflow.

        For example, you can add a Boolean type field to the Data Sheet entity, and when you check this field, an email will be sent.

        Create a Workflow with:
        • Target Entity: Data Sheet,
        • Trigger Type: After record updated,
        • Conditions: All > Checkbox field changed, Checkbox field equals true,
        • Action: Execute Formula Script.
        In this action, paste these formulas:
        Code:
        $productName = string\concatenate('Datasheet-', productId, '.pdf');
        $contactEmailAddress = record\attribute('Contact', contactId, 'emailAddress');
        
        $documentId = record\findOne('Document', 'createdAt', 'desc', 'name=', $productName);
        
        $emailId = record\create('Email',
        'to', $contactEmailAddress
        'status', 'Draft',
        'attachmentsIds', $documentId
        );
        
        ext\email\applyTemplate($emailId, '[your_email_template_id]'); // paste here your Email Template ID
        ext\email\send($emailId);​
        Check this solution, please. If you encounter any errors with this, I'll be happy to help.​

        Comment

        • RaptorBlue
          Junior Member
          • Oct 2022
          • 10

          #5
          Thanks lazovic, but if I understand it correctly, I am not able to edit the message before sending.
          Also, for Workflows I need the Advanced Pack, right? Is there a trial version?

          Comment

          • lazovic
            Super Moderator
            • Jan 2022
            • 809

            #6
            RaptorBlue,

            Yes, you won't be able to edit the email, as it will be sent automatically using only the Email Template.

            Workflow is indeed a feature of the Advanced Pack extension. You can test this extension for a whole month using the cloud version of EspoCRM.​

            Comment

            Working...