How to add document link in Email Template

Hello,

Can anyone tell me on how to add a document link in the Email Template?

Scenario: When an Employee applies for a leave application, the follow via email is checked. An Email Template called Leave approval notification will be sent to Leave approver. But there is no link to that particular document in the notification mail.

So, is it possible to include document link, so that leave approvers can click on that link and get to that document? Same thing should be applicable for Leave status notification template.

Please help.

Thanks & Regards,
Sujay

1 Like

I think this can help in your email template (any email template or doctype);

<a href="{{ frappe.utils.get_url_to_form(doc.doctype, doc.name) }}">{{ doc.employee_name}}'s Leave Application </a>

Cheers

3 Likes

Hello,

Can you please tell me where should I include this code?

Should be included in your email alert (notification in v11). Here’s an example of a notification I use

<h3>New Customer Issue</h3>

<p>A new customer issue has been recorded for {{ doc.customer }} by {{ doc.owner }}. Kindly view details below and take necessary action.</p>

<p> Link: <a href="{{ frappe.utils.get_url_to_form(doc.doctype, doc.name) }}">{{ doc.customer }} Customer Issue </a> </p>

<!-- show last comment -->
{% if comments %}
Last comment: {{ comments[-1].comment }} by {{ comments[-1].by }}
{% endif %}

<h4>Details</h4>

<ul>
<li>Customer: {{ doc.customer }}
<li>Priority: {{ doc.priority }}
</ul>

4 years later I want to achieve something like this, but: It seems that in newer versions (I’m using v14) {{frappe.utils.get_url_to_form(doc.doctype, doc.name)}}“>{{doc.name}}” returns a private url that can only be accessed by people who are logged in. But I want to achieve something like “View this in your browser” when “Send document web view link in email” is enabled. Where the link contains some kind of key that makes the file accessible without being logged in. Any idea how i could achieve this? Thanks :slight_smile:

Here it is : {{frappe.utils.get_url_to_form(doc.doctype, doc.name)}

Sadly with this code it only works when you are logged in, i need something where you can access the invoice pdf online over a link (without being logged in in erpnext)

This is an exemple for Delivery Note :

{{frappe.get_url()}}/delivery_note/{{doc.name}}?key={{frappe.get_doc(doc.doctype, doc.name).get_signature()}}

2 Likes

Unfortunately, this does not work in ERPNext v15. You can’t add frappe directly to quotation or sales order templates. Only Jinja2 markup.

There has to be a way to do this as the standard ugly email template has a “View in browser” link

Yes you can? … could you share what issue you are having

I am trying to get the public html link for a quote (like the standard one does). My code looks something like this:

% if language == "fr-CA" %}
Bonjour {{ customer_name }},

Veuillez trouver ci-joint le devis {{ name }}, valable jusqu'au {{ valid_till }}.

Voir le devis : {{frappe.get_url()}}/Quotation/{{doc.name}}?key={{frappe.get_doc(doc.doctype, doc.name).get_signature()}}

Cordialement,  
{{ company }}

{% else %}
Dear {{ customer_name }},

Please find attached quotation {{ name }}, valid until {{ valid_till }}.

View Quote: {{frappe.get_url()}}/Quotation/{{doc.name}}?key={{frappe.get_doc(doc.doctype, doc.name).get_signature()}}

Best regards,  
{{ company }}
{% endif %}

But it doesn’t link the quote in browser, instead it redirects to a login page.

Thanks for your help

In System Settings
Enable ‘Allow older web view links’

1 Like

Brilliant my friend. That fixed it. Didn’t even have to include the frappe block. Auto generated at the end of the email.

Thanks a bunch!

1 Like