I would like to create a dynamically rows in a table in an html file from a google apps-script with variable. and for this I would like to have some helps as I'm really new on this. at this moments mail email as fixed rows with variable on each rows therefore if they are empty I have empty rows in my table.
I have the function called var_rows I have variables in cells to be the added in cells on the html table. I have also created a countable variable that will populate the rows if it's not 0 and do not add the rows if the count is 0.
var_row.gs
function var_rows() {
//
// https://www.youtube.com/watch?v=h2z13YE3kJg
// Source pour le code
//
//
// variable pour la creation du fichier HTML
var emailTemp = HtmlService.createTemplateFromFile("gsuite_demande_validation");
//variable pour appeller le "sheet" du fichier actif
var ws = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("VALIDATION.FORM");
// la variable d'appel pour l'objet dans l'onglet final
var wsSettings = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("VALIDATION.FORM");
var from = wsSettings.getRange("$C$2").getValue();
var mail = wsSettings.getRange("$C$3").getValue();
var cc = wsSettings.getRange("$C$4").getValue();
var sujet = wsSettings.getRange("$C$5").getValue();
var action1 = wsSettings.getRange("$C$16").getValue();
var utilisateur1 = wsSettings.getRange("$C$17").getValue();
var count2 = wsSettings.getRange("$D$23").getValue();
var action2 = wsSettings.getRange("$C$22").getValue();
var utilisateur2 = wsSettings.getRange("$C$23").getValue();
emailTemp.from = from;
emailTemp.mail = mail;
emailTemp.cc = cc;
emailTemp.sujet = sujet;
emailTemp.action1 = action1;
emailTemp.utilisateur1 = utilisateur1;
emailTemp.count2 = count2;
emailTemp.action2 = action2;
emailTemp.utilisateur2 = utilisateur2;
GmailApp.createDraft(
mail,
sujet,
"Votre messagerie ne support pas HTML",
{name: nom, htmlBody: htmlMessage,cc: cc, from: from});
}
I have an email template called
gsuite_demande_validation.html
<table style="border-collapse: collapse; width: 83.662%; height: 1129px;" border="1">
<tbody>
<tr style="height: 47px;">
<td style="height: 47px; width: 37.7105%;">
<p dir="ltr"><span style="font-size: 10pt; font-family: Roboto, RobotoDraft, Helvetica, Arial, sans-serif;">Action 1 :</span></p>
</td>
<td style="height: 47px; width: 62.1212%;">
<p dir="ltr"><span style="font-size: 10pt; font-family: Roboto, RobotoDraft, Helvetica, Arial, sans-serif;"><?= action1 ?></span></p>
</td>
</tr>
<tr style="height: 47px;">
<td style="height: 47px; width: 37.7105%;">
<p dir="ltr"><span style="font-family: Roboto, RobotoDraft, Helvetica, Arial, sans-serif;">Utilisateur défini</span></p>
</td>
<td style="height: 47px; width: 62.1212%;">
<p dir="ltr"><span style="font-size: 10pt; font-family: Roboto, RobotoDraft, Helvetica, Arial, sans-serif;"><?= utilisateur1 ?></span></p>
</td>
</tr>
<!--another action here if count2 is not 0 -->
<tr style="height: 15.75pt;">
<td style="height: 19px; width: 37.7105%;"> </td>
<td style="height: 19px; width: 62.1212%;"> </td>
</tr>
<tr style="height: 47px;">
<td style="height: 47px; width: 37.7105%;">
<p dir="ltr"><span style="font-size: 10pt; font-family: Roboto, RobotoDraft, Helvetica, Arial, sans-serif;">Action 2 :</span></p>
</td>
<td style="height: 47px; width: 62.1212%;">
<p dir="ltr"><span style="font-size: 10pt; font-family: Roboto, RobotoDraft, Helvetica, Arial, sans-serif;"><?= action2 ?></span></p>
</td>
</tr>
<tr style="height: 47px;">
<td style="height: 47px; width: 37.7105%;">
<p dir="ltr"><span style="font-family: Roboto, RobotoDraft, Helvetica, Arial, sans-serif;">Utilisateur défini</span></p>
</td>
<td style="height: 47px; width: 62.1212%;">
<p dir="ltr"><span style="font-size: 10pt; font-family: Roboto, RobotoDraft, Helvetica, Arial, sans-serif;"><?= utilisateur2 ?></span></p>
</td>
<tr style="height: 15.75pt;">
<td style="height: 19px; width: 37.7105%;"> </td>
<td style="height: 19px; width: 62.1212%;"> </td>
</tr>
</tbody>
</table>
It will be nice to have a code generating the rows according to the information contenned in the action variables then populating the email with the additioned rows if variable exist. Thank you for your help.

