I have a button called "Assign Back to Originator". This button is used when a rep is done working on a case and needs to assign it back to the creator of the case. The button will then assign the creator of the case as the owner. How can I throw an error of "You are already the case owner" when the creator ID and the owner ID is the same when they try to click the "Assign Back to Originator" button?
This is the code I have so far:
{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")}
if ({!Case.OwnerId=Case.CreatedById}){
alert('You are already the owner of the case');
} else {
var caseObj = new sforce.SObject("Case");
caseObj.Id = '{!Case.Id}';
caseObj.OwnerId = '{!Case.CreatedById}';
var result = sforce.connection.update([caseObj]);
if (result[0].success=='false') {
alert(result[0].errors.message);
} else {
//location.reload(true);
alert ('This case will be assigned back to the creator. You will no longer have access to this case.');
window.location = '/500/o';
}
}