1

I created a custom docusign button on a salesforce object to send a document. the button is a javascript button. I received the error "Unterminated String Constant". What's supposed to happen is the user clicks the button and a custom subject line and message would appear.

{!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='';
//*************************************************//
SES = '1';
SEM = '1';
CES = '{!Risk_Management__c.Legal_Contract_Name__c}:Old Republic-UM/UIM Coverage Selection/Rejection Forms';

CEM = 'Dear {!Risk_Management__c.SignerName__c}

Thank you for inquiring about the uninsured motorists (UM) and underinsured motorists (UIM) coverage options available to you through your Old Republic Insurance Company auto insurance policy.  You have notified us of your intention to reject coverage where possible and/or to select the minimum statutory combined single limit in states that do not allow rejection.

To move forward with this coverage intent, we require that you complete written coverage selection/rejection forms.  Please use the DocuSign application to review and sign the selection/rejection forms applicable to your auto insurance policy.  Once you complete the signing process, you will have an opportunity to print the completed selection/rejection forms for your records.  Your completed forms will automatically be sent to us.  We ask that you sign the coverage selection/rejection forms no later than [INSERT DATE].

Should you have any questions regarding this email or the DocuSign application, please contact {!User.Name} at {!User.Phone}.

We appreciate your prompt attention to our request.';

//********* Page Callout (Do not modify) *********//
window.location.href = "/apex/dsfs__DocuSign_CreateEnvelope?DSEID=0&SourceID={!Risk_Management__c.Id}&CES="+CES+"&CEM="+CEM+"&SES="+SES+"&SEM="+SEM;
2
  • You can't have string literals in a javascript variable.
    – Adrian Larson
    Nov 4, 2016 at 15:00
  • Adrian, please explain? I'm new to javascript and would like to understand what you mean.
    – Chad
    Nov 4, 2016 at 15:00

3 Answers 3

4

You can't declare multi-line strings in Javascript. Here is your issue:

 CEM = 'Dear {!mergeField}

 More Text

 ...';

Instead, you could concatenate the string if you want to break it up onto multiple lines:

CEM = 'Dear {!mergeField}' +
    'More Text' +
    '...';

If you want to include literal line breaks in the string, you can include the '\n' character. It's unclear how Docusign will handle that, though.

CEM = 'Dear {!mergeField}' + '\n\n' +
    'More Text' + '\n\n' +
    '...';
2

The problem 1 is with multi-line string literal.

'line 1 line 2'

has to be transformed to 'line 1\n'+ 'line 2'

Problem 2: if you pass something as url params - use encodeURI

try this

{!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='';
//*************************************************//
SES = '1';
SEM = '1';
CES = encodeURI('{!Risk_Management__c.Legal_Contract_Name__c}:Old Republic-UM/UIM Coverage Selection/Rejection Forms');

CEM = encodeURI('Dear {!Risk_Management__c.SignerName__c}\n\n'
+'Thank you for inquiring about the uninsured motorists (UM) and underinsured motorists (UIM) coverage options available to you through your Old Republic Insurance Company auto insurance policy.  You have notified us of your intention to reject coverage where possible and/or to select the minimum statutory combined single limit in states that do not allow rejection.\n\n'
+'To move forward with this coverage intent, we require that you complete written coverage selection/rejection forms.  Please use the DocuSign application to review and sign the selection/rejection forms applicable to your auto insurance policy.  Once you complete the signing process, you will have an opportunity to print the completed selection/rejection forms for your records.  Your completed forms will automatically be sent to us.  We ask that you sign the coverage selection/rejection forms no later than [INSERT DATE].\n\n'
+'Should you have any questions regarding this email or the DocuSign application, please contact {!User.Name} at {!User.Phone}.\n\n'
+'We appreciate your prompt attention to our request.');

//********* Page Callout (Do not modify) *********//
window.location.href = "/apex/dsfs__DocuSign_CreateEnvelope?DSEID=0&SourceID={!Risk_Management__c.Id}&CES="+CES+"&CEM="+CEM+"&SES="+SES+"&SEM="+SEM;
1
  • thank you Pav. I tried this but now I get Invalid character
    – Chad
    Nov 4, 2016 at 15:11
1

To create mulitline strings in JavaScript, you should use template literals.

{!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='';
//*************************************************//
SES = '1';
SEM = '1';
CES = '{!Risk_Management__c.Legal_Contract_Name__c}:Old Republic-UM/UIM Coverage Selection/Rejection Forms';

CEM = `Dear {!Risk_Management__c.SignerName__c}

Thank you for inquiring about the uninsured motorists (UM) and underinsured motorists (UIM) coverage options available to you through your Old Republic Insurance Company auto insurance policy.  You have notified us of your intention to reject coverage where possible and/or to select the minimum statutory combined single limit in states that do not allow rejection.

To move forward with this coverage intent, we require that you complete written coverage selection/rejection forms.  Please use the DocuSign application to review and sign the selection/rejection forms applicable to your auto insurance policy.  Once you complete the signing process, you will have an opportunity to print the completed selection/rejection forms for your records.  Your completed forms will automatically be sent to us.  We ask that you sign the coverage selection/rejection forms no later than [INSERT DATE].

Should you have any questions regarding this email or the DocuSign application, please contact {!User.Name} at {!User.Phone}.

We appreciate your prompt attention to our request.`;

//********* Page Callout (Do not modify) *********//
window.location.href = "/apex/dsfs__DocuSign_CreateEnvelope?DSEID=0&SourceID={!Risk_Management__c.Id}&CES="+CES+"&CEM="+CEM+"&SES="+SES+"&SEM="+SEM;

See also Creating multiline strings in JavaScript on Stack Overflow.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .