+ Start a Discussion
Swapna MistrySwapna Mistry 

Custom Button Error Message - Javascript

I've got a custom button called Submit on a Custom object called Incoming Fund. This button will write the current Date/Time to the Submitted Date field. This is working fine. 

User-added image


BUT - I need to return an error message to the user and NOT write the Submitted Date if Collections/MS Case is blank = "Case is required to submit" I need to code this into my button code, but I dont know how. 

Please help! 

{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")} 
var newRecords = []; 
var c = new sforce.SObject("Incoming_Fund__c"); 
c.id ="{!Incoming_Fund__c.Id}"; 
c.Submitted_Date__c = new Date().toISOString(); 
newRecords.push(c); 
result = sforce.connection.update(newRecords); 
window.location.reload();
Nayana KNayana K
{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")} 

if("{!Incoming_Fund__c.REPLACE_THIS_WITH_API_NAME_OF_COLLECTION_MSCASE_FIELD}" == null )
{
    alert("Case is required to submit");
}
else
{
    var newRecords = []; 
    var c = new sforce.SObject("Incoming_Fund__c"); 
    c.id ="{!Incoming_Fund__c.Id}"; 
    c.Submitted_Date__c = new Date().toISOString(); 
    newRecords.push(c); 
    result = sforce.connection.update(newRecords); 
    window.location.reload();
}