Setting Subject in Mail Script for Email Client Template

pardhiv
Tera Contributor

Can we set a subject in Mail Script for Email Client Template (sys_email_client_template) . Tried below

 

pardhiv_0-1666330935104.png

 

 

 

 

pardhiv_1-1666330956480.png

 

 

14 REPLIES 14

adriantan08
Giga Expert

I was able to modify the subject a bit by doing:

RE: ${subject}

 

Maybe you can test by doing javascript:dosomething? 

Hi @adriantan08 

 

Can you elaborate on how you managed to modify the subject in email client template? Using email script or some other way? In either case, it will be helpful if you could shed some light.

 

Thanks in advance.

 

Regards

Himanshu

I solved it with a global "UI script" modifying the email client subject field with jQuery. I know it is a hack but it worked and I had to solve it. Here is my script:

if (window.location.href.indexOf("email_client.do") > -1 &&
    window.location.href.indexOf("sn_customerservice_masterdata") > -1) {
   
    var currentUrl = window.location.href;
    var urlParams = new URLSearchParams(currentUrl);
    var recordSysId = urlParams.get('sysparm_sys_id');      
    var replySysId  = urlParams.get('reply_sys_id');        
       
    if (replySysId) {      
        var gr = new GlideRecord("sys_email");
        gr.addQuery("sys_id", replySysId);
        gr.query(function(email) {
            if (email.next()) {    
                jQuery("input#subject").val("RE: " + email.subject);
            }
        });
    }
    else if (recordSysId) {
        var gr = new GlideRecord("sn_customerservice_masterdata");
        gr.addQuery("sys_id", recordSysId);
        gr.query(function(rec) {
            if (rec.next()) {      
                jQuery("input#subject").val("RE: " + rec.short_description);
            }
        });
    }
}

hverma2705
Tera Contributor

Hi @adriantan08 Can you please elaborate on how you changed the subject using email script? Are you saying that you used "javascript:mymethod()" where mymethod() is a method defined in some script include or you called email script somehow jusing javascript:dosomething?

 

Regards

Himanshu

Christian Engs1
Tera Contributor

I solved it with a global "UI script" modifying the email client subject field with jQuery. I know it is a hack but it worked and I had to solve it. Here is my script:

if (window.location.href.indexOf("email_client.do") > -1 &&
    window.location.href.indexOf("sn_customerservice_masterdata") > -1) {
   
    var currentUrl = window.location.href;
    var urlParams = new URLSearchParams(currentUrl);
    var recordSysId = urlParams.get('sysparm_sys_id');      
    var replySysId  = urlParams.get('reply_sys_id');        
       
    if (replySysId) {      
        var gr = new GlideRecord("sys_email");
        gr.addQuery("sys_id", replySysId);
        gr.query(function(email) {
            if (email.next()) {    
                jQuery("input#subject").val("RE: " + email.subject);
            }
        });
    }
    else if (recordSysId) {
        var gr = new GlideRecord("sn_customerservice_masterdata");
        gr.addQuery("sys_id", recordSysId);
        gr.query(function(rec) {
            if (rec.next()) {      
                jQuery("input#subject").val("RE: " + rec.short_description);
            }
        });
    }
}