Reply
Regular Contributor
Staci
Posts: 62
0

Take Case button functionality

Please see my button code below.  What we want is for Status and Substatus to only change is Closed <> True.  Is there a way to make this happen?

 

 

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

var caseObj = new sforce.SObject("Case");
caseObj.Id = '{!Case.Id}';
caseObj.OwnerId = '{!$User.Id}';

caseObj.Status = 'In Progress'
caseObj.Substatus__c = 'Open with Support Advocates';

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


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

Super Contributor
Rahul Sharma
Posts: 846
0

Re: Take Case button functionality

Perform the logic when, the case is not closed! Use if statement for that.

I believe by closed you mean status is not closed.

Updated Code:

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

if('{!Case.Status}' != 'Closed'){
    var caseObj = new sforce.SObject("Case");
    caseObj.Id = '{!Case.Id}';
    caseObj.OwnerId = '{!$User.Id}';

    caseObj.Status = 'In Progress'
    caseObj.Substatus__c = 'Open with Support Advocates';

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


    if (result[0].success=='false') {
        alert(result[0].errors.message);
    } else {
        window.parent.location.href="/{!Case.Id}/e?retURL=%2F{!Case.Id}";
    }
}
else{
    alert('This functionality does not supports closed case!!');
}

 

- Rahul