How to fetch table info from expense claim docType in email notification

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:

  1. The date at which the entry was created.
  2. 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 %}
        <th>Expense Claim Type</th>
      {% for expense in doc.expenses %}
        {% set expense_type_doc = frappe.get_doc("Expense Claim Type", expense.expense_type) %}
          <td>{{ loop.index }}</td>
          <td>{{ }}</td>
          <td>{{ expense.amount }}</td>
      {% endfor %}
{% 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.