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
Tarun MukhiaTarun Mukhia 

Need help with custom button

Hi,

We have a button. I want to add validation to it if "AR"  Or "Billing Address" fields is blank then stop user.
How can I add this as a seperate alert message "AR field is mandatory" & "Billing Address is Mandatory"?
Thanks
Tarun

{!requireScript("/soap/ajax/26.0/connection.js")} 
var proceed = true; 

if("{!Account.Account_Number__c}"!="") { 
alert("This Account has already been on-boarded"); 
proceed=false; 
} else if("{!Account.Validation_Requested_On__c}"!="") { 
proceed = confirm("It appears that a user has already requested on-boarding for this Account (Requested By: {!Account.Validation_Requested_By__c}, on {!Account.Validation_Requested_On__c}).\n\nWould you still like to request that this Account be on-boarded?"); 

 
Best Answer chosen by Tarun Mukhia
Raj VakatiRaj Vakati
Can you try something like  below 
 
{!requireScript("/soap/ajax/26.0/connection.js")} 
var proceed = true; 

if("{!Account.Account_Number__c}"!="") { 
alert("This Account has already been on-boarded"); 
proceed=false; 
}else If("{!Account.AR__c}"==""){
	alert("AR field is mandatory");
	proceed=false; 
}
else If("{!Account.BillingAddress}"==""){
	alert("BillingAddress field is mandatory");
	proceed=false; 
}
else ("{!Account.Validation_Requested_On__c}"!="") { 
proceed = confirm("It appears that a user has already requested on-boarding for this Account (Requested By: {!Account.Validation_Requested_By__c}, on {!Account.Validation_Requested_On__c}).\n\nWould you still like to request that this Account be on-boarded?"); 
}


 

All Answers

Raj VakatiRaj Vakati
Can you try something like  below 
 
{!requireScript("/soap/ajax/26.0/connection.js")} 
var proceed = true; 

if("{!Account.Account_Number__c}"!="") { 
alert("This Account has already been on-boarded"); 
proceed=false; 
}else If("{!Account.AR__c}"==""){
	alert("AR field is mandatory");
	proceed=false; 
}
else If("{!Account.BillingAddress}"==""){
	alert("BillingAddress field is mandatory");
	proceed=false; 
}
else ("{!Account.Validation_Requested_On__c}"!="") { 
proceed = confirm("It appears that a user has already requested on-boarding for this Account (Requested By: {!Account.Validation_Requested_By__c}, on {!Account.Validation_Requested_On__c}).\n\nWould you still like to request that this Account be on-boarded?"); 
}


 
This was selected as the best answer
Tarun MukhiaTarun Mukhia
Thank you Raj, but it did not work. I have used proper merge fields. See below 

User-added image

{!requireScript("/soap/ajax/26.0/connection.js")} 
var proceed = true; 

if("{!Account.Account_Number__c}"!="") { 
alert("This Account has already been on-boarded"); 
proceed=false; 
}else If("{!Account.AR_Type__c}"==""){ 
alert("Please select AR Type"); 
proceed=false; 

else If("{!Account.BillingAddress}"==""){ 
alert("Please enter Billing Address"); 
proceed=false; 

else ("{!Account.Validation_Requested_On__c}"!="") { 
proceed = confirm("It appears that a user has already requested on-boarding for this Account (Requested By: {!Account.Validation_Requested_By__c}, on {!Account.Validation_Requested_On__c}).\n\nWould you still like to request that this Account be on-boarded?"); 


 
Raj VakatiRaj Vakati
Can you modify this code 
 
{!REQUIRESCRIPT("/soap/ajax/21.0/connection.js")}

var proceed = true; 
var aName ='{!Account.Name}' ;
var atype ='{!Account.Type}' ;
var aRating ='{!Account.Rating}' ;


if(aName==="undefined") { 
alert("This Account has already been on-boarded"); 
proceed=false; 
}else if(atype==="undefined"){ 
alert("Please select AR Type"); 
proceed=false; 
} 
else if(aRating==="undefined"){ 
alert("Please enter Billing Address"); 
proceed=false; 
} 
else{ 
proceed = confirm("It appears that a user has already "); 
}

 
Tarun MukhiaTarun Mukhia
Hi Raj,

Your first solution worked. I was selecting the Billing Address field, which is a combination of many fields. When I selcted Billing Street field, it worked. 
Appeciate your help ! 
Thanks
Tarun