Customize 'Send with Docusign' Button in Salesforce

1.2k views Asked by At

I'm not a programmer but need help with javascript coding to pull off a customized 'Send with Docusign' button in salesforce. Im trying to have 3 primary functions built into it

1) It verifies that all necessary merge fields in salesforce are filled out before allowing the user to click the button 2) It looks at the value of one of the fields in salesforce and selects the appropriate template to use (China vs non-China). Each template is exactly the same in terms of fields being populated, just has different language for the region in the body. 3) It fills out the proper template with the salesforce merge fields and sends off the docusign email

I have custom button code from my initial set-up call with Docusign. I could use this code to just create two separate custom buttons, but I'd rather just have one button to remove the chance of user error. The code they provided me is here:

{!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='';
//*************************************************//
CES='This is my subject'; //Email Subject
CEM='This is my message'; //Email Message
LA='0'; //List Attachments from within Notes and Attachments - 0 or 1
DST='Template ID 1'; //Default Standard Template ID
OCO='Send'; //On Click Options - Send or Tag
CRL='Email~{!Account.Email_of_Signer__c};LastName~{!Account.Name_of_Signer__c};RoutingOrder~1;Role~R1';
CCRM='R1~Signer 1';
//********* Page Callout (Do not modify) *********//
window.location.href="/apex/dsfs__DocuSign_CreateEnvelope?DSEID=0&SourceID={!Account.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;
//*******************************************//

I then tried to piece together the logic needed to accomplish the 3 points above from other Salesforce and Docusign forums, but I can't get it to work. Again, I'm not a programmer so I'm probably making some very stupid mistakes here, but what I have is:

{!REQUIRESCRIPT("/apex/dsfs__DocuSign_JavaScript")}
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")}
//********* 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='';
//*************************************************//

//Verify that all fields are filled out
if(ISBLANK({!Account.Company_s_Legal_Name__c})||ISBLANK({!Account.Incorporation_Location__c})||ISBLANK({!Account.Principle_Place_of_Business__c})||ISBLANK({!Account.Name_of_Signer__c})||ISBLANK({!Account.Title_of_Signer__c})||ISBLANK({!Account.Email_of_Signer__c})){
alert ("Please feel out all fields in the 'NDA Requirements' section");
}
//Fill out and send Chinese template if incorporated in China or Hong Kong
elseif({!Account.China_or_HK__c}=="China"||{!Account.China_or_HK__c}=="Hong Kong"){
CES='This is my subject'; //Email Subject
CEM='This is my message'; //Email Message
LA='0'; //List Attachments from within Notes and Attachments - 0 or 1
DST='Tempalte ID 1'; //Default Standard Template ID
OCO='Send'; //On Click Options - Send or Tag
CRL='Email~{!Account.Email_of_Signer__c};LastName~{!Account.Name_of_Signer__c};RoutingOrder~1;Role~R1';
CCRM='R1~Signer 1';

//********* Page Callout (Do not modify) *********//
window.location.href="/apex/dsfs__DocuSign_CreateEnvelope?DSEID=0&SourceID={!Account.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;
//*******************************************//
}
//Otherwise fill out and send Non-china template
else{
CES='This is my subject'; //Email Subject
CEM='This is my message'; //Email Message
LA='0'; //List Attachments from within Notes and Attachments - 0 or 1
DST='Template ID 2'; //Default Standard Template ID
OCO='Send'; //On Click Options - Send or Tag
CRL='Email~{!Account.Email_of_Signer__c};LastName~{!Account.Name_of_Signer__c};RoutingOrder~1;Role~R1';
CCRM='R1~Signer 1';

//********* Page Callout (Do not modify) *********//
window.location.href="/apex/dsfs__DocuSign_CreateEnvelope?DSEID=0&SourceID={!Account.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;
//*******************************************//
}

My Docusign Onboarding Success Consultant indicated that the stackoverflow community may be able to help out here. If so I would be extremely grateful. Even if someone with coding experience can tell me that this is a difficult thing to pull off or not would be helpful so I can know if I have a chance of getting it to work on my own or not.

1

There are 1 answers

0
Mike Raven On

I believe merge field should be quoted in conditional statements. Instead of:

elseif({!Account.China_or_HK__c}=="China"||{!Account.China_or_HK__c}=="Hong Kong"){

Try

elseif("{!Account.China_or_HK__c}"=="China"||"{!Account.China_or_HK__c}"=="Hong Kong"){

And do the same in all your if else elseif