1

I am trying to select the appropriate email template using javascript on a custom button. Here is a stripped down version of my code:

var template; 
var type = "{!My_Custom_Object__c.My_Field__c}"; 
if(type == "Quick") { 
template = "00XV0000000DlRB"; 
}
location.replace('/email/author/emailauthor.jsp?p3_lkid={!My_Custom_Object__c.Id}&p24=james.hyland1@verizon.net&p5=&template_id=template')

If I replace the end of the last line with template_id=00XV0000000DlRB, it works; but if I use the variable template, it says template_id contains a character that is not allowed. Any ideas? Thanks.

2

template is a varible, so you should concatenate it to literal string by using "+".

 '...emplate_id='+template

Try this:

var template='';
if("{!My_Custom_Object__c.My_Field__c}" == "Quick") { 
   template = "&template_id=00XV0000000DlRB"; 
}
location.replace('/email/author/emailauthor.jsp?p3_lkid={!My_Custom_Object__c.Id}&p24=james.hyland1@verizon.net'+template)
  • Thanks. I'm confused by the "'" before the plus. Is that syntax correct? – JimH Jun 17 '13 at 19:04
  • the quotes were justo to highlight the symbol. you only have to concatenate doing: "your-url"+valiable – Martin Borthiry Jun 17 '13 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.