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
Michele ToscanoMichele Toscano 

Javascript custom button: getting unexpected token { error

My sytax is not getting an error when I check it via my javascript button - however, when I click the button which executes it - it throws an unexpected token { error.  What am I doing wrong?

//Subregion consideration 
    If ({!ISPICKVAL(Account.Sub_Region__c, 'NA')
      } ||(!ISPICKVAL(Account.Sub_Region__c, 'SA')
      } ||(!ISPICKVAL(Account.Sub_Region__c, 'EU')
      } ||(!ISPICKVAL(Account.Sub_Region__c, 'ME')
      } ||(!ISPICKVAL(Account.Sub_Region__c, 'CN')
      } ||(!ISPICKVAL(Account.Sub_Region__c, 'AS')
      } ||(!ISPICKVAL(Account.Sub_Region__c, 'AN')
      }) {
//there is a bunch more code here.......if......blah blah
//Subregion consideration 
     } else
       alert('A valid subregion is required for customer conversion.');
Michele ToscanoMichele Toscano
It now throws a Error: Syntax error. Missing ')' on the line where ‘AN’ is mentioned…..I tried removing it- but it didn’t like that either. Same message – same line.
Alain CabonAlain Cabon
Sorry.

== 'AN')    })    {
//Subregion consideration 
    If (   {! Account.Sub_Region__c} == 'NA'
        || {! Account.Sub_Region__c} == 'SA'
        || {! Account.Sub_Region__c} == 'EU'
        || {! Account.Sub_Region__c} == 'ME'
        || {! Account.Sub_Region__c} == 'CN'
        || {! Account.Sub_Region__c} == 'AS'
        || {! Account.Sub_Region__c} == 'AN')
    {
//there is a bunch more code here.......if......blah blah
//Subregion consideration 
     } else
       alert('A valid subregion is required for customer conversion.');

 
Michele ToscanoMichele Toscano
I have to use this syntax because it’s a picklist field. It doesn’t like == notation for picklists. I tried removing the }) – no errors on syntax but I still get the javascript unexpected token when pressing the button. I’ve put it back to my original – since both ways are not working. //Subregion consideration If ({!ISPICKVAL(Account.Sub_Region__c, 'NA') } ||(!ISPICKVAL(Account.Sub_Region__c, 'SA') } ||(!ISPICKVAL(Account.Sub_Region__c, 'EU') } ||(!ISPICKVAL(Account.Sub_Region__c, 'ME') } ||(!ISPICKVAL(Account.Sub_Region__c, 'CN') } ||(!ISPICKVAL(Account.Sub_Region__c, 'AS') } ||(!ISPICKVAL(Account.Sub_Region__c, 'AN') }) {
Alain CabonAlain Cabon
Hi Michele,

I don't have your complete source code.

https://success.salesforce.com/answers?id=90630000000D8sJAAS

If(ISPICKVAL(record.Resolution_Code__c,"Referred to Vendor") 

becomes

if("{!Case.Resolution_Code__c}" == "Referred to Vendor")

Simple or double quotes work in javascript.
     
If (  "{! Account.Sub_Region__c}" == "NA" )  // with double quotes 

I found this direct conversion very often for picklists (with or without quotes). It seems that double quotes is the better choice here.
Michele ToscanoMichele Toscano
I found the solution to be to store the picklist field in a variable and notate this way: if((subregn == 'NA')||(subregn == 'SA')||(subregn == 'EU')||(subregn == 'ME')||(subregn == 'CN')||(subregn == 'AS') ||(subregn == 'AN')){ ……..more code here……. } else alert('Please select a valid subregion for customer conversion.'); Regards, Michele Toscano Senior Applications Specialist Cabot Corporation Office: (678) 297-1455 Tip! To respond, either reply to this email or click this link: https://developer.salesforce.com/forums/ForumsMain?id=9060G000000MTEQ This e-mail and any attachments are for use by the intended recipient and may contain confidential, privileged or proprietary information. Any use, dissemination, distribution, or reproduction of this message by unintended recipients is prohibited. If you have received this e-mail in error, please notify the sender immediately by telephone or e-mail and delete the original message. Thank you.