0

I'm receiving the following error on the below button: "Unexpected token else"

The field is a picklist and called Approval_Status__c on the Opportunity. I want my DocuSign button to work when Approval_Status__c = "Contract draft completed. Needs contract to be executed." and to only display and alert "You must have Legal approval before you can send contract." when that field doesn't have the value.

{!REQUIRESCRIPT("/apex/dsfs__DocuSign_JavaScript")} 
{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")} 
if("{!Opportunity.Approval_Status__c}" == "Contract draft completed. Needs contract to be executed."){ 
var primaryContact = getOpportunityPrimaryContact('{!Opportunity.Id}'); 


if(primaryContact == null) { 
alert('Please mark a Primary Contact before using this button.'); 
} else { 


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

CES='Please Sign {!JSENCODE(Account.Name)}'; //Email Subject 
CEM='Please review and sign the attached Agreement. Thanks, {!JSENCODE(Opportunity.OwnerFullName)}'; //Email Message 
LA='1'; //List Attachments from within Notes and Attachments - 0 or 1 
DST=''; //Default Standard Template ID 
//RROS='1'; 
CCRM='r1~Signer 1;Evaluator~Signer 2;cc~CC'; 
CCTM='r1~Signer;Evaluator~Signer;cc~Carbon Copy'; 
//OCO='Send'; 

CRL='Email~adn@gmail.com;LastName~AD;RoutingOrder~1;Role~r1,Email~{!Opportunity.OwnerEmail};LastName~{!JSENCODE(Opportunity.Owner_Name__c)};Role~cc;RoutingOrder~2,Email~' + primaryContact.Email + ';LastName~' + primaryContact.Name + ';Role~Evaluator;RoutingOrder~3,Email~{!Opportunity.OwnerEmail};LastName~{!JSENCODE(Opportunity.Owner_Name__c)};Role~cc;RoutingOrder~4,LoadDefaultContacts~0'; 
//********* 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;
//*******************************************// 
} 


function getOpportunityPrimaryContact (oppId) { 
var result = sforce.connection.query("select Contact.Id, Contact.Email, Contact.Name from OpportunityContactRole where OpportunityId = '" + oppId + "' and IsPrimary = true"); 
if(!result || result['size'] != 1) { 
return null; 
} 

var contactRole = result.getArray('records')[0]; 

return contactRole.Contact; 
} 
else 
{ 
alert('You must have Legal approval before you can send contract.'); 
}
1
if(!result || result['size'] != 1) { 
return null; 
} 

var contactRole = result.getArray('records')[0]; 

return contactRole.Contact; 
} 
else 
{ 
alert('You must have Legal approval before you can send contract.'); 
}

The } before the else closes the function, so else is not expected. I think you meant as follows:

if(!result || result['size'] != 1) { 
  alert('You must have Legal approval before you can send contract.'); 
  return null; 
} 
var contactRole = result.getArray('records')[0]; 
return contactRole.Contact; 
} 
  • Thanks for pointing me in the right direction, that specific change didn't work, but I changed it to != at the top and had the else be the entire rest of javascript. I'll post what worked as an answer. – JakeDocu May 18 '17 at 22:19
0

got this to work:

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

{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")} if("{!Opportunity.Approval_Status__c}" != "Contract draft completed. Needs contract to be executed."){ alert('You must have Legal approval before you can send contract.'); } else {

var primaryContact = getOpportunityPrimaryContact('{!Opportunity.Id}');

if(primaryContact == null) { alert('Please mark a Primary Contact before using this button.'); } else {

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

CES='Please Sign {!JSENCODE(Account.Name)}'; //Email Subject CEM='Please review and sign the attached Agreement. Thanks, {!JSENCODE(Opportunity.OwnerFullName)}'; //Email Message LA='1'; //List Attachments from within Notes and Attachments - 0 or 1 DST=''; //Default Standard Template ID //RROS='1'; CCRM='r1~Signer 1;Evaluator~Signer 2;cc~CC'; CCTM='r1~Signer;Evaluator~Signer;cc~Carbon Copy'; //OCO='Send';

CRL='Email~ad@gmail.com;LastName~Ad;RoutingOrder~1;Role~r1,Email~{!Opportunity.OwnerEmail};LastName~{!JSENCODE(Opportunity.Owner_Name__c)};Role~cc;RoutingOrder~2,Email~' + primaryContact.Email + ';LastName~' + primaryContact.Name + ';Role~Evaluator;RoutingOrder~3,Email~{!Opportunity.OwnerEmail};LastName~{!JSENCODE(Opportunity.Owner_Name__c)};Role~cc;RoutingOrder~4,LoadDefaultContacts~0'; //********* 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; //*******************************************// } } function getOpportunityPrimaryContact (oppId) { var result = sforce.connection.query("select Contact.Id, Contact.Email, Contact.Name from OpportunityContactRole where OpportunityId = '" + oppId + "' and IsPrimary = true");

if(!result || result['size'] != 1) { return null; }

var contactRole = result.getArray('records')[0];

return contactRole.Contact; }

  • What did you change, exactly? Please do not just dump your code. – Adrian Larson May 18 '17 at 22:21
  • changed the == to != and had the else contain the entirety of the button functionality, also removed a } – JakeDocu May 19 '17 at 22:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.