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
Mikhail Nitko 5Mikhail Nitko 5 

Simultaneous Case Acceptance solution?

Hi folks,

I created a case system for my university to work with student cases and I'm having an issue where advisors accept a case simultaneously and the ownership bounces around, while the student and advisors are confused.

To resolve this, I created an accept button that checks whether the owner of the case is a Queue or a User, and to block ownership change if another User owns the case.

But while this works in the vast majority of cases, I can't seem to get it to be perfect, and we still have a few cases per day where the student's case gets bounced around.
Can anyone suggest how I may improve my Accept button code? .. should I have it check ownership twice at the top before proceeding?

Code: 
{!REQUIRESCRIPT("/soap/ajax/28.0/connection.js")} 
var objCase = sforce.connection.query("SELECT Id, OwnerId, Case_Owner_s__c from Case where id ='{!Case.Id}' limit 1"); 
var records = objCase.getArray("records"); 
var caseOwner = records[0].OwnerId; 
var caseOwnerName = records[0].Case_Owner_s__c; 

if(caseOwner.substring(0,3)=='005'){ 
alert("This case has already been accepted by " + caseOwnerName +" and is not in a Queue."); 
} 
else 
{ 
var caseObj = new sforce.SObject("Case"); 
caseObj.Id = '{!Case.Id}'; 
caseObj.OwnerId = '{!$User.Id}'; 
caseObj.One_Stop_Counter__c = "{!TEXT($User.Assigned_Counter__c)}"; 
caseObj.Display_Screen_Suffix__c = "see " + '{!User.FirstName}'+" at Counter "+'{!TEXT($User.Assigned_Counter__c)}'; 
var result = sforce.connection.update([caseObj]); 

if (result[0].success=='false'){ 
alert(result[0].errors.message); 
} 
else { 
window.parent.location.href="/{!Case.Id}"; 
} 
}

Thank you,
Mikhail