Disable the onclick JavaScript button once clicked #inSalesforce

Disable the onclick JavaScript button once clicked

Solution: Show an alert based on certain criteria:

Let's create a custom button named 'custom close case' in Case object and add this new JavaScript button in the layout (Note: javascript is not supported in lightning (only classic), you can create a similar vf page and make it available for lightning page)

{!REQUIRESCRIPT("/soap/ajax/52.0/connection.js")}

   var oppObj = new sforce.SObject("Case"); 
    cObj.Id = '{!Case.Id}'; 
    if('{!Case.Status}' == "Closed"){
        alert("Status is already closed. You cannot make any changes");     
    }
    else{
        cObj.Status = "Closed";
        var result = sforce.connection.update([cObj]); 
        if (result[0].success=='false') {
             alert(result[0].errors.message);
        } else {
             location.reload(true);
    }
}

Comments