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
AK123AK123 

Custom Java button - If statement

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!

Dhaval PanchalDhaval Panchal
Instead of below

if (caseObj.ATL_Pass__c==null) {
caseObj.ATL_Pass__c='{!User.Id}'}

try this


if (caseObj.ATL_Pass__c==null) {
caseObj.ATL_Pass__c="{!User.Id}"}
Dhaval PanchalDhaval Panchal
{!REQUIRESCRIPT("/soap/ajax/26.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); 
}

 

AK123AK123

Thanks Dhaval, however it did not work. The IF statement is still not working correctly, please advise.