Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

322
Visualizações
Google Apps Script: Scriplets on HTML Template

I'm looking for a way to add a section inside my Html template that will be conditionally shown.

I've been looking at scriptlets but all the examples I found were related to "for" functions.

This is my code so far

<tbody>
<? console.log("assigment_letter: " + assigment_letter)?>
<? assigment_letter == "" ? ?>
<tr style="font-size:14px;text-align:center;color:black">
<td style="padding:5px 40px;border: 1px solid #ddd;">Assigment Letter</td>
<td style="padding:5px 40px;border: 1px solid #ddd;">NOT FOUND</td>
</tr>
<? : "" ?>    
</tbody>

In the console log I'm validating that indeed the value from the variable assigment letter is blank and depending on that, I'd like to show a new row inside the table I'm buidling.

However I'm getting the following error.

SyntaxError: Unexpected token ';' at RejectedRequestEmail(Rejected Email:16:49) at onChange(Code:691:11)

It does not tell me exactly in which line of the Html the evaluate function is getting the error

Here is my function that evalutes this html template in case needed

function RejectedRequestEmail(email_obj){
  const htmlTemplateAgent = HtmlService.createTemplateFromFile('Email Reject Notification');
  htmlTemplateAgent.requesting_user_name = email_obj.requesting_user_name;
  htmlTemplateAgent.invoice_id = email_obj.invoice_id;
  htmlTemplateAgent.client_name = email_obj.client_name;
  htmlTemplateAgent.beneficiary_name = email_obj.beneficiary_name;
  htmlTemplateAgent.invoice_amount = email_obj.invoice_amount;
  htmlTemplateAgent.assigment_letter = email_obj.assigment_letter;
  htmlTemplateAgent.invoice_product_match = email_obj.invoice_product_match;
  htmlTemplateAgent.prohibited_items = email_obj.prohibited_items;
  htmlTemplateAgent.client_verified = email_obj.client_verified;
  htmlTemplateAgent.beneficiary_verified = email_obj.beneficiary_verified;
  htmlTemplateAgent.bank_verified = email_obj.bank_verified;
  htmlTemplateAgent.reviewer_name = email_obj.reviewer_name;
  
  const htmlForNotification = htmlTemplateAgent.evaluate().getContent();     
  
}

Thanks

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In your situation, how about the following modification?

Modified script:

When you want to use the ternary operator, how about the following modification? In this modification, the scriptlet of <?!= ... ?> is used.

<tbody>
<? console.log("assigment_letter: " + assigment_letter)?>
<?!= assigment_letter == "" ? `<tr style="font-size:14px;text-align:center;color:black">
<td style="padding:5px 40px;border: 1px solid #ddd;">Assigment Letter</td>
<td style="padding:5px 40px;border: 1px solid #ddd;">NOT FOUND</td>
</tr>` : "" ?>
</tbody>

Or, when you want to use the if statement, how about the following modification? In this modification, the scriptlet of <? ... ?> is used.

<tbody>
<? console.log("assigment_letter: " + assigment_letter)?>
<? if (assigment_letter == "") { ?>
<tr style="font-size:14px;text-align:center;color:black">
<td style="padding:5px 40px;border: 1px solid #ddd;">Assigment Letter</td>
<td style="padding:5px 40px;border: 1px solid #ddd;">NOT FOUND</td>
</tr>
<? } ?>
</tbody>

Reference:

  • HTML Service: Templated HTML
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda