You need to sign in to do that
Don't have an account?

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
{!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
Please use the below statement into your javascript-
var x = '{!TEXT($User.Region__c)}';
Thanks,
Gaurav
All Answers
Please use the below statement into your javascript-
var x = '{!TEXT($User.Region__c)}';
Thanks,
Gaurav
{!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