function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rachel BrozinickRachel Brozinick 

How to Escape a & Character with Javascript

Hello,

I have a custom javascript button I built and I'm having issues with & characters clearing our my email subject.  Alot of our Account Names have '&' symbol in their name. This is my code below.  I tried JSENCODE and JSINHTMLENCODE and that didn't seem to work.  Are there any other suggestions that I could use to escape the &?

{!REQUIRESCRIPT("/apex/dsfs__DocuSign_JavaScript")}

//********* Option Declarations (Do not modify )*********//
var RC = '';var RSL='';var RSRO='';var RROS='';var CCRM='';var CCTM='';var CCNM='';var CRCL=''; var CRL='';var OCO='';var DST='';var LA='';var CEM='';var CES='';var STB='';var SSB='';var SES='';var SEM='';var SRS='';var SCS ='';var RES='';
//*************************************************//

//Adding Notes & Attachments
var LA='0';

//Custom Email Subject
var CES='Re: Agreement for On-Site Mobile Services from TestCompany, Inc.:';

//Custom Email Message
var CEM='{!JSENCODE(Account.Name)}\\n{!Contact.Name}\\n{!JSENCODE(Contact.MailingStreet)}\\n{!Contact.MailingCity}, {!Contact.MailingState} {!Contact.MailingPostalCode}\\n\\nRe: Agreement for On-Site Mobile Services\\n\\nPlease find attached our Agreement for Services (agreement) for {!Opportunity.Account}. The Agreement outlines the services to be provided by TestCompany, fee schedule and our general terms and conditions for your review and electronic signature.\\n\\nOn behalf of TestCompany, we look forward to the opportunity to serve your organization.\\n\\n{!Opportunity.OwnerFullName}\\n{!Opportunity.OwnerTitle}\\nexaminetics\\n{!Opportunity.Owner_Street_Address__c}\\n{!Opportunity.Owner_Address__c}\\n{!Opportunity.OwnerPhone}\\n{!Opportunity.OwnerEmail}\\nwww.testcompany.com';


//********* Page Callout (Do not modify) *********//
window.location.href ="/apex/dsfs__DocuSign_CreateEnvelope?DSEID=0&SourceID={!Opportunity.Id}&RC="+RC+"&RSL="+RSL+"&RSRO="+RSRO+"&RROS="+RROS+"&CCRM="+CCRM+"&CCTM="+CCTM+"&CRCL="+CRCL+"&CRL="+CRL+"&OCO="+OCO+"&DST="+DST+"&CCNM="+CCNM+"&LA="+LA+"&CEM="+CEM+"&CES="+CES+"&SRS="+SRS+"&STB="+STB+"&SSB="+SSB+"&SES="+SES+"&SEM="+SEM+"&SRS="+SRS+"&SCS="+SCS+"&RES="+RES;
KevinPKevinP
JSHTMLENCODE should work, with a merge syntax of something like {!JSHTMLENCODE(Account.Name)} but if that fails, you can do a string replace in your Account.Name in the controller replacing the & character with

%26

which is the HTMLEncoding for &