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

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 ? 

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

“”"

Hello ${user.firstName}, some more email html content

A Table example
First Name ${user.firstName}
Last Name ${user.lastName}
""".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

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 ? 

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

Hello ${user.firstName} ...etc

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()

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

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.

alright , thank you for your answer.