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
Sarah Boggio 3Sarah Boggio 3 

OnClick JavaScript error when building a Send with DocuSign button

I am trying to build a custom Send with DocuSign button that will perform three actions when clicked:
  1. Make sure all necessary Order Form fields are populated
  2. Populate the form with field merge data from Salesforce
  3. Identify which type of Subscription Order to send, and 
  4. Route the Order to the appropriate customer and internal Signing Group
I am getting the following Error: "A problem with the OnClick JavaScript for this button or link was encountered: missing ) after argument list" 

Here is all of my code. I have never used JavaScript before so this may be completely wrong but I bought a JavaScript Udemy class over the weekend to try and accomplish this goal. Any assistance you could provide would be greatly appreciated. Thank you!
Code:
{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")}

//Verify that all fields are filled out
if(ISBLANK({!Opportunity.Subscription__c})||
ISBLANK({!Opportunity.Product__c})||
ISBLANK({!Opportunity.Payment_Terms__c})||
ISBLANK({!Opportunity.Project_City__c})||
ISBLANK({!Opportunity.Delivery__c})||
ISBLANK({!Opportunity.Payment_Terms__c})||
ISBLANK({!Opportunity.Primary_Contact__c})||
ISBLANK({!Opportunity.Accounting_Contact__c})||
ISBLANK({!Opportunity.Amount}))||
{
alert ("Please fill out all fields in the Order Form Information and Contract Detail sections.");
}
//Fill out and send Consultant Subscription template if the Subscription is Consultant
elseif({!Opportunity.Subscription__c}=="Consultant Subscription"||
{
CES='Please DocuSign: StreetLight Data Consultant Subscription'; //Email Subject
CEM='Attached is the StreetLight Data Subscription order for your signature. Thank you!'; //Email Message
LA='0'; //List Attachments from within Notes and Attachments - 0 or 1
DST='11647cd6-93eb-456a-94d1-9e0a4b7303b1'; //Default Standard Template ID
OCO='Send'; //On Click Options - Send or Tag
CRL='Email~(!Opportunity.Primary_Contact__c};LastName~{!Opportunity.Primary_Contact__c};RoutingOrder~1;Role~R1';
CCRM='Customer Signer~Signer 1';StreetLight Signer~Signer 2';

//********* 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;
//*******************************************//
}
//Verify that all fields are filled out
if(ISBLANK({!Opportunity.Subscription__c})||
ISBLANK({!Opportunity.Product__c})||
ISBLANK({!Opportunity.Payment_Terms__c})||
ISBLANK({!Opportunity.Project_City__c})||
ISBLANK({!Opportunity.Delivery__c})||
ISBLANK({!Opportunity.Payment_Terms__c})||
ISBLANK({!Opportunity.Primary_Contact__c})||
ISBLANK({!Opportunity.Accounting_Contact__c})||
ISBLANK({!Opportunity.Amount}))||
{
alert ("Please fill out all fields in the Order Form Information and Contract Detail sections.");
}

//Fill out and send Pay-per-use Subscription template if incorporated the Subscription is Pay-per-use
elseif({!Opportunity.Subscription__c}=="Pay-per-use Subscription"||
{
CES='Please DocuSign: StreetLight Data Pay-per-use Subscription'; //Email Subject
CEM='Attached is the StreetLight Data Subscription order for your signature. Thank you!; //Email Message
LA='0'; //List Attachments from within Notes and Attachments - 0 or 1
DST='07a29bf3-225e-494d-8c55-88fa5822e960'; //Default Standard Template ID
OCO='Send'; //On Click Options - Send or Tag
CRL='Email~{!Opportunity.Primary_Contact__c};LastName~{!Opportunity.Primary_Contact__c};RoutingOrder~1;Role~R1';
CCRM='Customer Signer~Signer 1';StreetLight Signer~Signer 2';

//********* 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;
//*******************************************//
}

Thank you!
Cheers,
Sarah

P.S. Apologies for posting this question here but DocuSign support doesn't provide JavaScript assistance and StackOverflow was not the kindest with my question. 
Best Answer chosen by Sarah Boggio 3
Dev_AryaDev_Arya
Hi Sarah,

Regarding your error, I looked in to the code and figured out few syntax errors. There are few brackets missing and some placed at wrong position,
I will advice, just format the code using your IDE formatter, and you will be able to solve such problem easily. :-)

I am not sure about the logic, but you could try the code below,
{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")}

//Verify that all fields are filled out
if(ISBLANK({!Opportunity.Subscription__c}) ||
    ISBLANK({!Opportunity.Product__c})||
    ISBLANK({!Opportunity.Payment_Terms__c})||
    ISBLANK({!Opportunity.Project_City__c})||
    ISBLANK({!Opportunity.Delivery__c})||
    ISBLANK({!Opportunity.Payment_Terms__c})||
    ISBLANK({!Opportunity.Primary_Contact__c})||
    ISBLANK({!Opportunity.Accounting_Contact__c})||
    ISBLANK({!Opportunity.Amount}))
{
    alert ("Please fill out all fields in the Order Form Information and Contract Detail sections.");
}
//Fill out and send Consultant Subscription template if the Subscription is Consultant
elseif({!Opportunity.Subscription__c}==="Consultant Subscription")
{
    CES='Please DocuSign: StreetLight Data Consultant Subscription'; //Email Subject
    CEM='Attached is the StreetLight Data Subscription order for your signature. Thank you!'; //Email Message
    LA='0'; //List Attachments from within Notes and Attachments - 0 or 1
    DST='11647cd6-93eb-456a-94d1-9e0a4b7303b1'; //Default Standard Template ID
    OCO='Send'; //On Click Options - Send or Tag
    CRL='Email~(!Opportunity.Primary_Contact__c};
    LastName~{!Opportunity.Primary_Contact__c};
    RoutingOrder~1;
    Role~R1';
    CCRM='Customer Signer~Signer 1';
    StreetLight Signer~Signer 2';

    //********* 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;
    //*******************************************//
}
//Verify that all fields are filled out
if(ISBLANK({!Opportunity.Subscription__c})||
    ISBLANK({!Opportunity.Product__c})||
    ISBLANK({!Opportunity.Payment_Terms__c})||
    ISBLANK({!Opportunity.Project_City__c})||
    ISBLANK({!Opportunity.Delivery__c})||
    ISBLANK({!Opportunity.Payment_Terms__c})||
    ISBLANK({!Opportunity.Primary_Contact__c})||
    ISBLANK({!Opportunity.Accounting_Contact__c})||
    ISBLANK({!Opportunity.Amount}))
{
    alert ("Please fill out all fields in the Order Form Information and Contract Detail sections.");
}

//Fill out and send Pay-per-use Subscription template if incorporated the Subscription is Pay-per-use
elseif({!Opportunity.Subscription__c}==="Pay-per-use Subscription")
{
    CES='Please DocuSign: StreetLight Data Pay-per-use Subscription'; //Email Subject
    CEM='Attached is the StreetLight Data Subscription order for your signature. Thank you!; //Email Message
    LA='0'; //List Attachments from within Notes and Attachments - 0 or 1
    DST='07a29bf3-225e-494d-8c55-88fa5822e960'; //Default Standard Template ID
    OCO='Send'; //On Click Options - Send or Tag
    CRL='Email~{!Opportunity.Primary_Contact__c};
    LastName~{!Opportunity.Primary_Contact__c};
    RoutingOrder~1;
    Role~R1';
    CCRM='Customer Signer~Signer 1';
    StreetLight Signer~Signer 2';

    //********* 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;
    //*******************************************//
}
There were lot of '~' signs in your code, please correct them with the respective operator. Also in your window.location.href path, there is multiple reference to the same argument. For ex: SRS. 

Hope this helps. Cheers, Dev  
 

All Answers

Dev_AryaDev_Arya
Hi Sarah,

Regarding your error, I looked in to the code and figured out few syntax errors. There are few brackets missing and some placed at wrong position,
I will advice, just format the code using your IDE formatter, and you will be able to solve such problem easily. :-)

I am not sure about the logic, but you could try the code below,
{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")}

//Verify that all fields are filled out
if(ISBLANK({!Opportunity.Subscription__c}) ||
    ISBLANK({!Opportunity.Product__c})||
    ISBLANK({!Opportunity.Payment_Terms__c})||
    ISBLANK({!Opportunity.Project_City__c})||
    ISBLANK({!Opportunity.Delivery__c})||
    ISBLANK({!Opportunity.Payment_Terms__c})||
    ISBLANK({!Opportunity.Primary_Contact__c})||
    ISBLANK({!Opportunity.Accounting_Contact__c})||
    ISBLANK({!Opportunity.Amount}))
{
    alert ("Please fill out all fields in the Order Form Information and Contract Detail sections.");
}
//Fill out and send Consultant Subscription template if the Subscription is Consultant
elseif({!Opportunity.Subscription__c}==="Consultant Subscription")
{
    CES='Please DocuSign: StreetLight Data Consultant Subscription'; //Email Subject
    CEM='Attached is the StreetLight Data Subscription order for your signature. Thank you!'; //Email Message
    LA='0'; //List Attachments from within Notes and Attachments - 0 or 1
    DST='11647cd6-93eb-456a-94d1-9e0a4b7303b1'; //Default Standard Template ID
    OCO='Send'; //On Click Options - Send or Tag
    CRL='Email~(!Opportunity.Primary_Contact__c};
    LastName~{!Opportunity.Primary_Contact__c};
    RoutingOrder~1;
    Role~R1';
    CCRM='Customer Signer~Signer 1';
    StreetLight Signer~Signer 2';

    //********* 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;
    //*******************************************//
}
//Verify that all fields are filled out
if(ISBLANK({!Opportunity.Subscription__c})||
    ISBLANK({!Opportunity.Product__c})||
    ISBLANK({!Opportunity.Payment_Terms__c})||
    ISBLANK({!Opportunity.Project_City__c})||
    ISBLANK({!Opportunity.Delivery__c})||
    ISBLANK({!Opportunity.Payment_Terms__c})||
    ISBLANK({!Opportunity.Primary_Contact__c})||
    ISBLANK({!Opportunity.Accounting_Contact__c})||
    ISBLANK({!Opportunity.Amount}))
{
    alert ("Please fill out all fields in the Order Form Information and Contract Detail sections.");
}

//Fill out and send Pay-per-use Subscription template if incorporated the Subscription is Pay-per-use
elseif({!Opportunity.Subscription__c}==="Pay-per-use Subscription")
{
    CES='Please DocuSign: StreetLight Data Pay-per-use Subscription'; //Email Subject
    CEM='Attached is the StreetLight Data Subscription order for your signature. Thank you!; //Email Message
    LA='0'; //List Attachments from within Notes and Attachments - 0 or 1
    DST='07a29bf3-225e-494d-8c55-88fa5822e960'; //Default Standard Template ID
    OCO='Send'; //On Click Options - Send or Tag
    CRL='Email~{!Opportunity.Primary_Contact__c};
    LastName~{!Opportunity.Primary_Contact__c};
    RoutingOrder~1;
    Role~R1';
    CCRM='Customer Signer~Signer 1';
    StreetLight Signer~Signer 2';

    //********* 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;
    //*******************************************//
}
There were lot of '~' signs in your code, please correct them with the respective operator. Also in your window.location.href path, there is multiple reference to the same argument. For ex: SRS. 

Hope this helps. Cheers, Dev  
 
This was selected as the best answer
Sarah Boggio 3Sarah Boggio 3
HI Dev, Thank you for your speedy response and updating my syntax issues. I don't know JavaScript at all and am only piecing this together from articles online and questions asked on forums and the 8 hour Udemy JavaScript class I bought last week to finish this project. So, if there are any other suggestions you'd make, I'd appreciate hearing them as I've exhausted my current knowledge set. :) Cheers, Sarah
Dev_AryaDev_Arya
Hi Sarah, 
no problem, its a start and you will get better in time. Javascript is fun and one can control pages quite easily. 
Regarding your code, did you resolve the error, or the problem still persists? let us know, otherwise please mark the question as solved.
One of my fav links to check for JS resources is 
http://jstherightway.org/
You can take full advantage of vast knowledge available on this website.

In future if you go for lightning, try out this trailhead
https://trailhead.salesforce.com/modules/lex_dev_lc_basics/units/lex_dev_lc_basics_forms
This makes checking form fields so easy.

Cheers,Dev