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

How to change default subject in emails depending on doctype


#1

In an Issue or Opportunity doc, when we compose a new email message, the subject field defaults to contain the ISS- or OPTY- ids.

We’d like to have our own custom subjects for different doctypes. To what doctype should I add a custom script for this? And what events should I use as trigger for the script?

also, sample code would be very helpful pls… or links to other discussions here (I tried searching, but I might have missed them since I’m not really sure what I’m looking for)


#2

You can go to the Naming Series doctype and select whichever DocType’s naming series you want to change


You’ll see that Opportunity previously had ‘OPTY-’ which I changed to ‘OPPO-’


#3

Thanks for the reply @Zlash65. That’s not exactly what I want to do though. I don’t want to change the naming series for the Opportunity or Issue doctype.

What I want to do is to prevent and/or to customize the automatic additions to the email subject when we send an email from these doctypes.

2018-01-23_1411

In the above example, the subject for this Issue is Your statement of account only. But when you try to compose an email, the email subject line is automatically added with the words “Issue:” in the beginning and the Issue ID “(#ISS-00021)” at the end.

We don’t want that. We would like to have only the original address we’ve entered for the Issue itself.

Of course, we can manually change this email subject before sending the email. But it gets annoying having to change this every single time just because something is automatically adding this here.


#4

My bad! I guess you can start from here, every DocType in the end gets passed to here and this is where the subject field is set accordingly. Maybe you can tweak it to compose your own kind of subject ?


#5

Thanks! This is a good starting point indeed.


#6

@Zlash65, I see this behavior is part of the core, hard-coded functionality. I haven’t tried overriding these things from a custom app.

Would you have a recommendation on a good way to override this? I’d like my custom code/functionality to survive updates.


#7

Is there a way to do this? We just want to change the verbiage in the subject line when Sales order and Sales Invoices are sent to our customers. Anyone know how to do this? I’m on ERPNext Cloud.


#8

Hi,

I did this to overwrite and change differents values in the email modal, you can do something like this in your doctype js file:

frappe.ui.form.on("Quotation", {
    onload: function(frm) {

        cur_frm.page.menu.find("a:contains("+__("Email")+")").on('click', function() {
           setTimeout(() => {
               $('*[data-fieldname="subject"]').val("Test subject")
           },500); 
        });

    });
}

Maybe it is not the best solution, but your are not overwritting part of the core. I hope that it helps you.