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
Melissa Parker 03Melissa Parker 03 

a problem with the OnClick JavaScript for this button or link was encountered: invalid or unexpected token

Hello Everyone,

I have created a custom button with code to update the Docusign Email Subject to "Please Docusign "Contract_Name". When attempting to test the button I receive the following error:

User-added image

This is the code in which I created: 
{!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=''; 
//*************************************************// 
// Custom Email Subject (default in config) 
CES = 'Please DocuSign: {!REVVY__MnContract__c.Name}'; // 
//********* 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="+CRC 
L+"&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; 
//*******************************************//

I followed the instructions provided by Docusign which they also provided a sample code to start with.
https://08d1d92f490618f41c65-8fb00e97ac499a7066a18ce9c66b019b.ssl.cf2.rackcdn.com/DocuSign_for_Salesforce_Custom_Button_Logic.pdf.

Can someone please assist? I'm pretty new to Java Script. Thanks.



 
tommy.coutetommy.coute
I just encountered the same problem when trying to create a JS button that validates a long text area field. After playing around and searching a bit, I found that the "invalid or unexpected token" error was occurring when a variable in my JS was passed a value containing line breaks (or new lines).

I was able to fix this by sanitizing the input within the JS code with the "JSENCODE" visualforce function... so instead of:
var str = '{!Long_Text_Area__c)}'; 
if(str != '') { ...

Try:
var str = '{!JSENCODE(Long_Text_Area__c)}'; 
if(str != '') { ...