ERPNext Foundation ERPNext Cloud User Manual Blog Discuss Frappé* Donate

To add child table in alert


#1

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?


#2

@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’


#3

@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?


#4

@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) }}

#5

Thank you @max_morais_dmm . I will check and revert.

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


#6

@Deven_Shah, Im sorry for the double typo!

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

#7

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.


#8

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


#9

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


#10

Hi,

Any Input here ?

Regards,


#11

@Deepak

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

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