Hello folks,
I am trying to create an email notification for expense claim docType. I was succesful in fetching the employee who raised an expense claim by using {{ doc.employee_name }}
, however, I am required to fetch the following info:
- The date at which the entry was created.
- The table named “expenses” with the items entered.
I tried jinja tags such as follows:
{{ doc.expenses }}
{{ expenses }}
But to no avail, all the email messages are showing only the above-mentioned code, thus unable to fetch the entries. Kindly please suggest a solution to this.
Thank you for your valuable time.
I’ve figured out on my own, ignore the html not being prettified, here’s the code you are going to need in your email body:
**This is a test mail.**
A new Expense Claim has been created on {{ doc.posting_date }} with the following details:
{% if doc.expenses %}
<table>
<thead>
<tr>
<th>No.</th>
<th>Date</th>
<th>Expense Claim Type</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
{% for expense in doc.expenses %}
{% set expense_type_doc = frappe.get_doc("Expense Claim Type", expense.expense_type) %}
<tr>
<td>{{ loop.index }}</td>
<td>{{ expense_type_doc.name }}</td>
<td>{{ expense.amount }}</td>
<td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>No expenses found.</p>
{% endif %}
Total Claim Amount: {{ doc.total_claimed_amount }}
Please review the Expense Claim and take appropriate action.
The important thing to note here is that, some docType fields are links, essentially linking to another docType and thus fetching them on the basis of just field names won’t be enough. You need to get the docType which is linked, and then fetch the names.
I hope this helps.
I am also trying to customize the mails for expense claims. Expense claims are controlled by a simple workflow with “Send email” option turned on.
The email looks like the above which is pretty ugly and useless. How do I customize it? The code that you provided above - where do I put this code? Is it part of a workflow as well? Any help would be appreciated. Thx