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
Aravind RAravind R 

Getting not defined error in onclick javascript

I have below code to redirect to diffrent page based on user's region, region is a custom field picklist:

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
{!REQUIRESCRIPT('/soap/ajax/29.0/apex.js')} 
var x = {!TEXT($User.Region__c)}; 
if(x == 'India'){ 
window.open("/apex/page1"); 

else{ 
window.open("/apex/page2"); 
}

But I am getting "India is not defined" error. Please help me out.

Thanks in advance
Best Answer chosen by Aravind R
Gaurav_SrivastavaGaurav_Srivastava
Hi Aravind R,

Please use the below statement into your javascript-

var x = '{!TEXT($User.Region__c)}';

Thanks,
Gaurav

All Answers

Gaurav_SrivastavaGaurav_Srivastava
Hi Aravind R,

Please use the below statement into your javascript-

var x = '{!TEXT($User.Region__c)}';

Thanks,
Gaurav
This was selected as the best answer
Amit Chaudhary 8Amit Chaudhary 8
Please try below code

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
{!REQUIRESCRIPT('/soap/ajax/29.0/apex.js')} 
if("{!User.Region__c}" == "India") 

window.open("/apex/page1"); 

else{ 
window.open("/apex/page2"); 
}

NOTE:- I hope you are using above code on user object ?

Please check belpw post. I hope that will help u  
http://www.jitendrazaa.com/blog/salesforce/create-and-update-records-using-javascript-button-in-salesforce-ajax-toolkit/
https://developer.salesforce.com/docs/atlas.en-us.workbook.meta/workbook/button_1.htm

Please let us know if this will help u

Thanks
Amit Chaudhary