Question
I want to send a table in html
with selected values based on conditions in the fields by clicking a button. I'm a bit confused about how textByTemplate
works. I would like to use it to generate an html table. Could someone provide an example of how this (or something similar) can be implemented?
Answer
Adding two templates to System Tables - Print Templates
Template type Page
:
<table>
<thead>
<tr style="border: solid 1px #474747; padding: 5px;">
<th style="border: solid 1px #474747; padding: 5px;">No
</th>
<th style="border: solid 1px #474747; padding: 5px;">VIN
</th>
<th style="border: solid 1px #474747; padding: 5px;">Current mileage
</th>
<th style="border: solid 1px #474747; padding: 5px;">Mileage for replacement
</th>
<th style="border: solid 1px #474747; padding: 5px;">Remaining until replacement
</th>
<th style="border: solid 1px #474747; padding: 5px;">Type of work
</th>
</tr>
</thead>
<tbody>
{cars}
</tbody>
</table>
This is the general outline of the table where there will be repeating elements (rows)
Template type Element
:
<tr>
<td style="border: solid 1px #474747; padding: 5px;">{vehicle_number}
</td>
<td style="border: solid 1px #474747; padding: 5px;">{vin}
</td>
<td style="border: solid 1px #474747; padding: 5px;">{current_mileage} km
</td>
<td style="border: solid 1px #474747; padding: 5px;">{mileage_next} km
</td>
<td style="border: solid 1px #474747; padding: 5px;">{remaining_distance} km
</td>
<td style="border: solid 1px #474747; padding: 5px;">{type_of_work}
</td>
</tr>
Code for sending data to these forms (can be placed in a button or cron):
=: emailSend(to: $to; title: "Maintenance due soon"; body: $table)
to: listCreate(item: "blabla@mail.com"; item: "bla@bk.com" ; item: "blablabla@bk.com")
table: textByTemplate(template: "page_template_name"; data: $data)
data: rowCreate(field: "cars" = $innerrowlist)
innerrowlist: rowCreate(field: "template" = "element_template_name"; field: "data" = $inner_data)
inner_data: selectRowList(table: 'some_table_with_data'; field: 'vehicle_number'; field: 'vin'; field: 'current_mileage'; field: 'mileage_next'; field: 'remaining_distance'; field: 'type_of_work'; where: 'current_mileage' != ""; where: 'remaining_distance' <= 5000; order: 'vehicle_number' asc)