How can I create a dynamic message content in email notification

hello Comunity
in my custom app, i want to send some data in the content message like created by or get data from other doc based on linked field in the main doc of the notification

i have been trying to use frappe.get_doc() but it throw an error

is anyone can give me a hint how to achive that.

Hi @Gharieb:

Use jinja for that.
Example with notification based on ToDo doctype.

{% set user_doc = frappe.get_doc("User", doc.allocated_to) %}
Hi {{ user_doc.last_name }} . I am here. Where are you?

Hope this helps.

thanks @avc but that what i was doing and it shows me an error like so

i can not figure out where the bug is did i miss some thing
i just want to get some docs.

Hi @Gharieb:

Show how your notification is defined and doctype design …

this how my notification doc


and when i test it it works

the CMP-00096 is the company name
but when i’m trying to get the company doc by frappe.get_doc() it throw error

Use this

{% set company = frappe.get_doc("Company", doc.company) %}
This is the company name: {{company.company_name}}

still the same error do you have any idea what is error message mean

Please try and check it.

{% set company_name = frappe.db.get_value("Company", doc.company, "company_name") %}
This is the company name: {{ company_name }}

i tried it with set Send Alret on New when i’m trying to save the doc it show’s this error message
image
and when i try prview from notifucation page it show’s

Hi @Gharieb:

Seems it’s failing on develop branch :thinking:. It works well on version-15, I tried with last updates …
Some changes was included on notifications system recently, maybe related.

As workaround, you can create a server script for your doctype …

company_name = frappe.get_value("Company", doc.company, "company_name")
frappe.sendmail(
    recipients="recipient@mail.com", 
    sender="sender@mail.com", 
    subject="New support ticket was created", 
    message=f"Hey, {company_name} was created.", 
    delayed=False)```

hi @avc
I hope so it’s related to the develop branch only, I’ll try it up in a Test env. if not so i’ll go with the server script. thanks for your cooperation :slightly_smiling_face: