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
Richa_LearningRicha_Learning 

Java script - Unexpected token ILLegal

Hi,

I created a custom button that should redirect to different apex page based on the record type.
Example: If record type = a then it should redirect to "abc" page otherwise "xyz" page

But when i click on the button i get illiegal token error.
{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/23.0/apex.js")} 

var rtype;

if({!Account.RecordTypeId} == "012G0000000nKI7")
{
rtype = "/apex/Newcase?";
}
else 
{
    rtype = "/apex/oldcase?";

}

window.top.location.href = rtype ;

Please help.
Himanshu MaheshwariHimanshu Maheshwari
Try this :
 
{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/23.0/apex.js")} 

var rtype;

if("{!Account.RecordTypeId}" == "012G0000000nKI7")
{ 
       rtype = "/apex/Newcase?";
}
else 
{
    rtype = "/apex/oldcase?";
}

window.top.location.href = rtype ;

Have to put {!Account.RecordTypeId} in double qoutes

 
Deepak GulianDeepak Gulian
{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")}
var url ;
if ("{!Account.RecordTypeId}" == "012G0000000nKI7") {
    url = "/apex/Newcase?";
} else {
        url = "/apex/oldcase?";
}
parent.location.href = url;
thatheraherethatherahere
Hi Rich,

You just need to write down below code for your buttons's on click Javascript.
 
var rtype;
if("{!Account.RecordTypeId}" == "012G0000000nKI7"){
    rtype = "/apex/Newcase?";
}else{
    rtype = "/apex/oldcase?";
}
window.top.location.href = rtype ;

Here no need to include {!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")} OR {!REQUIRESCRIPT("/soap/ajax/23.0/apex.js")} script files.

Thanks,

- thatherahere