Send an email with Dynamic Table content displayed in it's Body

1
0
-1

Good morning ,

So here is the case :

-I want to figure out how to include a table (template that is gonna be filed with dynamic information retrieved from a backend service) in the body of an email sent from Bonita for different users (maybe we will use a connector in this case).

-The content of the table must be displayed in the body of the mail , not as an attachment.

Is there any suggestions to achieve this ?

1 answer

1
0
-1

Hi, you may use a Groovy script expression as message body with Groovy multi-string:

"""
<p>Hello ${user.firstName}, some more email html content</p>
<table>
    <thead>
        <tr>
            <th colspan="2">A Table example</th>
        </tr>
    </thead>
    <tbody>
         <tr>
            <td>First Name</td>
            <td> ${user.firstName}</td>
        </tr>
        <tr>
            <td>Last Name</td>
            <td> ${user.lastName}</td>
        </tr>
    </tbody>
</table>
"""
.toString()

Where user is a business or process variable.
Do not forget to enable html content checkbox in the connector configuration.

If you want to do more advanced templating, Groovy has built-in features for that !

HTH
Romain

Comments

Submitted by FatmaGh on Fri, 11/20/2020 - 15:38

Thank you for your answer !

I wanna ask you , It won't be an issue if the body message is too long for an email ( 6 columns and 26 rows ) , is there an option to store that dynamic content in a file or smth and then send it back as en email content ?

Submitted by romain.bioteau on Fri, 11/20/2020 - 16:19

It won't be an issue if the body message is too long for an email ( 6 columns and 26 rows )

This is a responsiveness issue with html table (that's why they are not used a lot anymore). Have a look here for html tips.

is there an option to store that dynamic content in a file or smth and then send it back as en email content

Yes, you can imagine reading the template from an external source. By example you may have a template file template.groovy stored on a public github repository.

template.groovy

<html>
  <body>
     <p>Hello ${user.firstName} ...etc</p>
  </body>
</html>

And use the groovy template engine like this:

import groovy.text.SimpleTemplateEngine

new SimpleTemplateEngine()
        .createTemplate('https://raw.githubusercontent.com/you/mail-templates/template.groovy'.toURL())
        .make([  //Create a map with the variable used in the template
                user:user
                ])
       .toString()
Submitted by FatmaGh on Fri, 11/20/2020 - 17:03

What about the aspect of document in Bonita , what is used for ? Can we use it to store the template in it or smth?

Submitted by romain.bioteau on Fri, 11/20/2020 - 18:16

You could, but I don't think it is a good idea as it will then be stored in database and quite painful to update.

Submitted by FatmaGh on Sat, 11/21/2020 - 17:26

alright , thank you for your answer.

Notifications