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
Mitchell McLaughlin 1Mitchell McLaughlin 1 

Illegal token on button action

Hello -
I'm trying to switch this URL action on the button to a javascript action. Before, whatever was in window.open (see below) was alone and it was set to the URL behavior.
I'm still getting an illegal token error. I don't see what is going wrong.


{!REQUIRESCRIPT("/soap/ajax/21.0/connection.js")} 

var leadAddress = '{!Lead.Address}'; 
var leadCity = '{!Lead.City}'; 
var leadState = '{!Lead.State}'; 
var leadCountry = '{!Lead.Country}'; 


if(leadAddress == null || leadAddress == ''){ 
alert('Please enter Address before clicking on this button'); 

else if(leadCity == null || leadCity == ''){ 
alert('Please enter City before clicking on this button'); 

else if(leadState == null || leadState == ''){ 
alert('Please enter State before clicking on this button'); 

else if(leadCountry == null || leadCountry == ''){ 
alert('Please enter Country before clicking on this button'); 

else{ 
window.open(' 
/a0J/e? 
CF00Nj00000091TUH={!Lead.FirstName &" "& Lead.LastName } 
&CF00Nj00000091TUH_lkid={!Lead.Id} 
&retURL=%2F{!Lead.Id} 
&saveURL=%2F{!Lead.Id} 
&RecordType=012j0000000pfbL 
&ent=01Ij0000001EVex 
&00Nj00000091TU6={!Lead.Company} 
&00Nj00000091TUQ=Pending'); 
}
Best Answer chosen by Mitchell McLaughlin 1
James LoghryJames Loghry
Yep, looks like you're using the Address compound field instead of the Street field for your address variable, and that's what is throwing the illegal token now.  The following worked for my test:
 
{!REQUIRESCRIPT("/soap/ajax/36.0/connection.js")} 

var leadAddress = '{!Lead.Street}'; 
var leadCity = '{!Lead.City}'; 
var leadState = '{!Lead.State}'; 
var leadCountry = '{!Lead.Country}'; 


if(leadAddress == null || leadAddress == ''){ 
alert('Please enter Street Address before clicking on this button'); 
} 
else if(leadCity == null || leadCity == ''){ 
alert('Please enter City before clicking on this button'); 
} 
else if(leadState == null || leadState == ''){ 
alert('Please enter State before clicking on this button'); 
} 
else if(leadCountry == null || leadCountry == ''){ 
alert('Please enter Country before clicking on this button'); 
} 
else{ 
var urlStr = '/a0J/e?' 
+ 'CF00Nj00000091TUH={!Lead.FirstName &" "& Lead.LastName }' 
+ '&CF00Nj00000091TUH_lkid={!Lead.Id}' 
+ '&retURL=%2F{!Lead.Id}' 
+ '&saveURL=%2F{!Lead.Id}' 
+ '&RecordType=012j0000000pfbL' 
+ '&ent=01Ij0000001EVex' 
+ '&00Nj00000091TU6={!Lead.Company}' 
+ '&00Nj00000091TUQ=Pending'; 

window.open(urlStr); 

}

 

All Answers

James LoghryJames Loghry
Mitchell,

The issue is you have line breaks in your window.open string, which JavaScript does not like.  Instead, it's expecting to find a closing single quote.  Replace the window.open call with the following, and you'll fix your ILLEGAL TOKEN error:
 
var urlStr = '/a0J/e?'  
    + 'CF00Nj00000091TUH={!Lead.FirstName &" "& Lead.LastName }'
    + '&CF00Nj00000091TUH_lkid={!Lead.Id}'
    + '&retURL=%2F{!Lead.Id}'
    + '&saveURL=%2F{!Lead.Id}'
    + '&RecordType=012j0000000pfbL'
    + '&ent=01Ij0000001EVex'
    + '&00Nj00000091TU6={!Lead.Company}'
    + '&00Nj00000091TUQ=Pending';

window.open(urlStr);

Also, when you post code on these forums (JS, Apex, Visualforce, whichever), please use the code format (< >) button.  This will help us easily read your code and copy and paste if need be.  Thanks!
Mitchell McLaughlin 1Mitchell McLaughlin 1
Okay perfect. I see it now. So I tested out filling in the street address and city, but once I left state blank and I expected it to say Fill in the State before clicking this button, but instead another illegal token.
 
{!REQUIRESCRIPT("/soap/ajax/21.0/connection.js")} 

var leadAddress = '{!Lead.Address}'; 
var leadCity = '{!Lead.City}'; 
var leadState = '{!Lead.State}'; 
var leadCountry = '{!Lead.Country}'; 


if(leadAddress == null || leadAddress == ''){ 
alert('Please enter Street Address before clicking on this button'); 
} 
else if(leadCity == null || leadCity == ''){ 
alert('Please enter City before clicking on this button'); 
} 
else if(leadState == null || leadState == ''){ 
alert('Please enter State before clicking on this button'); 
} 
else if(leadCountry == null || leadCountry == ''){ 
alert('Please enter Country before clicking on this button'); 
} 
else{ 
var urlStr = '/a0J/e?' 
+ 'CF00Nj00000091TUH={!Lead.FirstName &" "& Lead.LastName }' 
+ '&CF00Nj00000091TUH_lkid={!Lead.Id}' 
+ '&retURL=%2F{!Lead.Id}' 
+ '&saveURL=%2F{!Lead.Id}' 
+ '&RecordType=012j0000000pfbL' 
+ '&ent=01Ij0000001EVex' 
+ '&00Nj00000091TU6={!Lead.Company}' 
+ '&00Nj00000091TUQ=Pending'; 

window.open(urlStr); 

}

 
James LoghryJames Loghry
Copying that into a lead custom button on my org worked like a charm.  Did you happen to refresh the lead detail page to pick up your last changes?  Or did you post the latest JavaScript?
Mitchell McLaughlin 1Mitchell McLaughlin 1
Yeah what I last posted is what I have in my button java script code. if the street or city are null it throws the correct exceptions, but if they are filled in, it looks like all the other cases throw illegal token.
Mitchell McLaughlin 1Mitchell McLaughlin 1
User-added image
James LoghryJames Loghry
Yep, looks like you're using the Address compound field instead of the Street field for your address variable, and that's what is throwing the illegal token now.  The following worked for my test:
 
{!REQUIRESCRIPT("/soap/ajax/36.0/connection.js")} 

var leadAddress = '{!Lead.Street}'; 
var leadCity = '{!Lead.City}'; 
var leadState = '{!Lead.State}'; 
var leadCountry = '{!Lead.Country}'; 


if(leadAddress == null || leadAddress == ''){ 
alert('Please enter Street Address before clicking on this button'); 
} 
else if(leadCity == null || leadCity == ''){ 
alert('Please enter City before clicking on this button'); 
} 
else if(leadState == null || leadState == ''){ 
alert('Please enter State before clicking on this button'); 
} 
else if(leadCountry == null || leadCountry == ''){ 
alert('Please enter Country before clicking on this button'); 
} 
else{ 
var urlStr = '/a0J/e?' 
+ 'CF00Nj00000091TUH={!Lead.FirstName &" "& Lead.LastName }' 
+ '&CF00Nj00000091TUH_lkid={!Lead.Id}' 
+ '&retURL=%2F{!Lead.Id}' 
+ '&saveURL=%2F{!Lead.Id}' 
+ '&RecordType=012j0000000pfbL' 
+ '&ent=01Ij0000001EVex' 
+ '&00Nj00000091TU6={!Lead.Company}' 
+ '&00Nj00000091TUQ=Pending'; 

window.open(urlStr); 

}

 
This was selected as the best answer
Mitchell McLaughlin 1Mitchell McLaughlin 1
HA! Thank you! Solved.