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
sirwileysirwiley 

Need code/objects for custom button allowing: change status, change case owner, add comment

Need code/objects for custom "Escalate" button on the case detail page that opens a window to allow support users to complete the following fields on the case object:

 

  1. Change the status (escalation should be the only choice in the drop-down),
  2. Change the case owner, and
  3. Add a comment

We will try to find information ourselves but any guidance appreciated.

sirwileysirwiley

I've got this so far, which seems to work, for Custom Button, behavior:  execute javascript to just change status (See bottom below), but I need to open a new window, I guess, and allow user to select a different case owner and add a comment:  (not sure how to do this yet)

 

URLs for Change owner and new comment for a certain case:  (How to make these dynamic for this escalate button?)

 https://na9.salesforce.com/500E0000003mvi6/a?retURL=%2F500E0000003mvi6

https://na9.salesforce.com/00a/e?parent_id=500E0000003mvi6&retURL=%2F500E0000003mvi6

 

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

    var caseObj = new sforce.SObject("Case");
    caseObj.Id = '{!Case.Id}';
    caseObj.Status = 'Escalated';
    var result = sforce.connection.update([caseObj]);

    if (result[0].success=='false') {
         alert(result[0].errors.message);
    } else {
         location.reload(true);
    }

sirwiley2sirwiley2

The following is working but users would like:   the add comments window not open in a new tab, but wouldlike to stay in current tab like the behavior of the Close Case button. Need help with the syntax for changing this minor window opening preference.

 

I've tried scrUp and srcSelf but think these require apex objects.  Probably something simple but cant seem to get it working.

 

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

 

    var caseObj = new sforce.SObject("Case");

    caseObj.Id = '{!Case.Id}';

    parent.ID='{!Case.ParentId}'   

    caseObj.OwnerId = '00Gc0000000FXfv';

    caseObj.Status = 'Escalated';

   window.open('/00a/e?parent_id={!Case.Id}&retURL=/{!Case.Id}');

    var result = sforce.connection.update([caseObj]);

 

    if (result[0].success=='false') {

         alert(result[0].errors.message);

    } else {

         location.reload(true);

    }

VinceCVinceC
To get the behavior to stay in the current window you need to tweak your code a bit, example below.

{!REQUIRESCRIPT("/soap/ajax/21.0/connection.js")}
var caseObj = new sforce.SObject("Case");
caseObj.Id = '{!Case.Id}';
caseObj.Status = 'Escalated';
var result = sforce.connection.update([caseObj]);
if (result[0].success == 'false') {
    alert(result[0].errors.message);
} else {
    parent.ID = '{!Case.ParentId}';
    window.parent.location = ('/00a/e?parent_id={!Case.Id}&IsPublished=1&retURL=/{!Case.Id}');
}