Mail Script - Creating dynamic table based on MRVS
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 07:04 AM
Hi Folks,
I'm trying to create a table in mail script with values from a multirow variable set. I' trying to achieve this, because I need that my end users receive the list in theis e-mails.
I have this code below in my mail script:
(function runMailScript(current, template, email, email_action, event) {
var pessoas = JSON.parse(current.variables.u_colaboradores);
template.print('<table border="1" style="text-align:center">');
template.print('<tr><th>');
template.print('É funcionário?');
template.print('</th><th>');
template.print('Nome');
template.print('</th><th>');
template.print('Nome usuário');
template.print('</th><th>');
template.print('CPF');
template.print('</th><th>');
template.print('DEC');
template.print('</th></tr>');
for (var i = 0; i < pessoas.length; i++){
template.print('<tr><td>');
template.print(pessoas[i].is_employee);
template.print('</td><td>');
template.print(pessoas[i].nome);
template.print('</td><td>');
template.print(pessoas[i].user_id);
template.print('</td><td>');
template.print(pessoas[i].cpf);
template.print('</td><td>');
template.print(pessoas[i].dec);
template.print('</td></tr>');
}
template.print('</table>');
})(current, template, email, email_action, event);
When all the variables are fulfilled, this works fine, but when a variable is empty, my table broke. Probably because of my "for".
How can I make this dynamic?
0 REPLIES 0