title: Salesforce Button: How To Display An Error if Opportunity Stage Does Not Equal "Closed Won"
body: <p>I'm creating a DocuSign custom button within Salesforce. Attempting to add an error when some field values are not met before running the DocuSign button logic.</p>
  
  <p>My desired condition is if the pick list value of Opportunity Stage does not equal "Closed Won" THEN trigger an error message. else, execute the DocuSign custom button.</p>
  
  <p>I am very new to javascript and just started learning, so I apologize for the elementary questions and appreciate the feedback.</p>
  
  <p>My current script is below:</p>
  
  <pre><code>{!REQUIRESCRIPT("/apex/DocuSign_JavaScript")}
  
  var oppStage = "Closed Won";
  var error;
  {
  if ({!Opportunity.StageName}!=oppStage)
  
  {
  error = "Unable to send envelope. Opportunity Stage does not equal Closed won.";
  }
  else {
  //********* 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="Hello World";
  
  CRL='FirstName~{!URLENCODE(User.FirstName)};LastName~{!URLENCODE(User.LastName)};Email~{!URLENCODE(User.Email)};Role~OppOwner;RoutingOrder~2,LoadDefaultContacts~1';
  
  CCRM='Business User~Signer 1;OppOwner~Signer 2';
  
  LA='0';
  
  CEM='Hello World,\\n\\nThis should be a double line break.';
  
  
  //********* Page Callout (Do not modify) *********//
  window.location.href ="/apex/dsfs__DocuSign_CreateEnvelope?DSEID=0&amp;SourceID={!Opportunity.Id}&amp;RC="+RC+"&amp;RSL="+RSL+"&amp;RSRO="+RSRO+"&amp;RROS="+RROS+"&amp;CCRM="+CCRM+"&amp;CCTM="+CCTM+"&amp;CRCL="+CRCL+"&amp;CRL="+CRL+"&amp;OCO="+OCO+"&amp;DST="+DST+"&amp;CCNM="+CCNM+"&amp;LA="+LA+"&amp;CEM="+CEM+"&amp;CES="+CES+"&amp;SRS="+SRS+"&amp;STB="+STB+"&amp;SSB="+SSB+"&amp;SES="+SES+"&amp;SEM="+SEM+"&amp;SRS="+SRS+"&amp;SCS="+SCS+"&amp;RES="+RES;
  //*******************************************//
  }
  }
  </code></pre>
  
  <p>The current error message I receive is <em>"Qualification is not defined"</em>. </p>
  
  <p>Qualification is the current value of the pick list on my Opportunity. If I change this value, the error message will reflect it.</p>
  
  <p>Thanks in advance.</p>