To add child table in alert

Is it possible to add display child table in Email Alert? For eg.

Whether an email alert for Purchase Order can contain Purchase Order Item table?

@Deven_Shah yes!

the condition will be something like

len(doc.get('items', {'item_code': '122as'})) >0

It means that the code should run, when the items have a item_code = ‘122aa’

1 Like

@max_morais_dmm Thank you for quick reply. Please see following screen shots. Do you mean that I should put above mentioned code at the place shown in second picture?

@Daven_Shah, I’m sorry! Do you need render the table, right? I understood, build conditions based on child items, to render a table use:

{{ render_table('items', doc) }}

Thank you @max_morais_dmm . I will check and revert.

BTW, spelling on my name was incorrect (Just for info).

@Deven_Shah, Im sorry for the double typo!

{{ render_table(doc.meta.get_field("items"), doc) }}

Hi @max_morais_dmm , am trying to do the same, display child table when sending email of Sales Order. Sales Order also has a tables called items. However, when I tried the above code, was faced with : Error while evaluating Email Alert . Please fix your template.

Please advice if you have a way of displaying child table in email alert.

Thank you.

Hi Max,

I am new to ERPNext. I chanced upon your script. Thank you is helpful. Just wondering, if i would like to check for more items, how should I be coding it?

Would it be like len(doc.get(‘items’, {‘item_code’: ‘122as’, {‘item_code’: ‘second item’ })) >0

Thank you!
Boon Yar

Hi @max_morais_dmm

I was trying your code but I am getting following error while creating the sales order.

With below traceback.

Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/jinja.py”, line 77, in render_template
return get_jenv().from_string(template).render(context)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/jinja2/environment.py”, line 1008, in render
return self.environment.handle_exception(exc_info, True)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/jinja2/environment.py”, line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "

Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/jinja.py”, line 77, in render_template
return get_jenv().from_string(template).render(context)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/jinja2/environment.py”, line 1008, in render
return self.environment.handle_exception(exc_info, True)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/jinja2/environment.py”, line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "

Can you help that what is wrong here.

Regards

Hi,

Any Input here ?

Regards,

@Deepak

add this to the beginning of your template, on the email alert.

{%- from "templates/print_formats/standard_macros.html" import render_table -%} 

@max_morais_dmm

Thanks for the reply, now I have added the above line in beginning of the email notification and now I am getting below error.

Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/email/doctype/notification/notification.py”, line 310, in evaluate_alert
alert.send(doc)
File “/home/frappe/frappe-bench/apps/frappe/frappe/email/doctype/notification/notification.py”, line 119, in send
self.send_an_email(doc, context)
File “/home/frappe/frappe-bench/apps/frappe/frappe/email/doctype/notification/notification.py”, line 150, in send_an_email
message = frappe.render_template(self.message, context),
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/jinja.py”, line 77, in render_template
return get_jenv().from_string(template).render(context)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/jinja2/environment.py”, line 1008, in render
return self.environment.handle_exception(exc_info, True)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/jinja2/environment.py”, line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File “”, line 15, in top-level template code
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/jinja2/runtime.py”, line 579, in _invoke
rv = self._func(*arguments)
File “/home/frappe/frappe-bench/apps/frappe/frappe/./templates/print_formats/standard_macros.html”, line 27, in template
{%- set data = doc.get(df.fieldname)[df.start:df.end] -%}
TypeError: unhashable type

Please Suggest, your responses are appreciated.

Regards,

I am trying to use this condition on version 12 and I receive this error:

len(doc.get('autorizacoes_de_transito', {'vencimento_autorizacao': nowdate()})) > 0

any help in this