You need to sign in to do that
Don't have an account?
AK123
Custom Java Button
Hello, I am trying to write code for a custom button using Java, please see below:
{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")} var caseObj = new sforce.SObject("Lead"); caseObj.Id = '{!Lead.Id}'; caseObj.Rating = '2'; caseObj.Customer_Interest_Level__c= "Interested to learn more about FX"; caseObj.ATL__c= '{!User.Id}'; if (caseObj.ATL_Pass__c==null) { caseObj.ATL_Pass__c='{!User.Id}'} var result = sforce.connection.update([caseObj]); if (result[0].success=='false') { alert(result[0].errors.message); } else { location.reload(true); }
Basically I am trying: if ATL_pass__c = null, then update this field to the current user ID. If not, leave untouched. The conditional portion of this (in red above) does not seem to be working. It is changing the value of ATL_pass__c regardless if it is null or not. Please advise.
Thanks!
Try this:
{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")}
var caseObj = new sforce.SObject("Lead");
caseObj.Id = '{!Lead.Id}';
caseObj.Rating = '2';
caseObj.Customer_Interest_Level__c= "Interested to learn more about FX";
caseObj.ATL__c= '{!User.Id}';
if ('{!Lead.ATL_Pass__c}'=='' || '{!Lead.ATL_Pass__c}'==' ') {
caseObj.ATL_Pass__c='{!$User.Id}' // This should be a global variable
}
var result = sforce.connection.update([caseObj]);
if (result[0].success=='false') {
alert(result[0].errors.message);
} else {
location.reload(true);
}
I think you are missing to grab the ATL_Pass__c field value, if it is in a Lead try using the {!Lead.ATL_Pass__c} , and rememeber that in Javascript there is no null since its a front end language so you should compare it with ''.
cheers