You need to sign in to do that
Don't have an account?
Mikhail Nitko 6
OnClick Javascript to Refresh page and then check conditions for possible Alert
Hi folks,
I put a custom button on Salesforce cases that both Accepts a case and checks whether it the case is owned by a User or Queue, and gives an error when one user tries to take the case from another User, and not from a Queue.
The trouble is this button only works if one user opens the case after another has accepted it. But if both users open an unaccepted case, the button will unfortunately allow the case to first be taken by the first person and then the second, without alerting.
The code:
My original solution to this was to have the code in the Accept button refresh the page before running its User owner check, but this does not seem to be working either.
I was adding location.reload(true); before the User check.
Can anyone tell me why the refresh solution isn't working, or if there is another way to either do the refresh, or to execute my intentions?
I put a custom button on Salesforce cases that both Accepts a case and checks whether it the case is owned by a User or Queue, and gives an error when one user tries to take the case from another User, and not from a Queue.
The trouble is this button only works if one user opens the case after another has accepted it. But if both users open an unaccepted case, the button will unfortunately allow the case to first be taken by the first person and then the second, without alerting.
The code:
{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")} if('{!Case.OwnerId}'.substring(0,3)=='005'){ alert("This case is owned by " +'{!Case.Case_Owner_s__c}'+" 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}"; } }
My original solution to this was to have the code in the Accept button refresh the page before running its User owner check, but this does not seem to be working either.
I was adding location.reload(true); before the User check.
Can anyone tell me why the refresh solution isn't working, or if there is another way to either do the refresh, or to execute my intentions?
Try this code. Let me know if this works for you.
All Answers
Try this code. Let me know if this works for you.
The only thing I added was I had to change the Alert to retrieve and show the name of the owner from the live record, by adding this:
Thank you tons.