Thursday, May 23, 2013

The Quick Case Close Button

People often ask me how they can get around the Close Case page.  One option to do this is to replace the standard Close Case button with a custom button of your own.  It's remarkably easy to do! Here's how.

First, go to Setup->Cases->Buttons and Links and make a new custom button called Close Case.  Its Display Type should be set to Detail Page Button, its Behavior to Execute JavaScript, and its Content Source to OnClick JavaScript.

Now you need only paste the following JavaScript in there:

{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")}
var caseObj = new sforce.SObject("Case");
caseObj.Id = '{!Case.Id}';
caseObj.Status = 'Closed';
var result = sforce.connection.update([caseObj]);
if (result[0].success=='false') {
    alert(result[0].errors.message);
} else {
    location.reload(true);
}


This is assuming, of course, that you actually have a status called "Closed" -- but if you don't, don't despair -- just change the caseObj.Status = 'Closed'; line to a closed status that actually exists in your case status list.

Now edit your Case page layout.  Click on the Detail Page Buttons box and it will be highlighted, then click the Edit Properties button.  Here you'll be able to hide the standard Close Case button and show your new custom Close Case button. Finally test your new button by making a test case and closing it.  Voila!  The button sets the case to a closed status and reloads the page to give you feedback that in fact it was closed!  


Please note that because this trick uses the API, it will only work for Enterprise Edition and up, or for Professional Edition with the API add-on.

No comments:

Post a Comment