Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

326
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!