1

I have a requirement to run case assignment rule from javascript. I used the below code but the assignment rule does not run.

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

var updateRecord = []; 
var updateCaseRecord=[]; 
var caseToUpdate = new sforce.SObject("Case"); 

if('{!Case.Status}' != 'In Progress' ) {    
    alert('The Case cannot be reversed. A case can be reversed only when it is in "In Progress" Status');  
}  
else {      
    caseToUpdate.id ='{!Case.Id}';
    caseToUpdate.status = '{!Case.Previous_Case_Status__c}';
    assignObj = new sforce.SObject("AssignmentRuleHeader");     
    assignObj.useDefaultRule = 'true';
    sforce.connection.AssignmentRuleHeader = {}
    sforce.connection.AssignmentRuleHeader.useDefaultRule='true';
    //caseToUpdate.setOptions(assignObj);
    updateRecord.push(caseToUpdate);
    var result = sforce.connection.update(updateRecord); 
if (result[0].success=='false') {       
    alert(result[0].errors.message);    
} 
else {      
    location.reload();  
}    //End.  
} 
window.location.reload();
1
  • What is the error/issue that you are getting when you execute this code? Commented Oct 13, 2017 at 10:24

1 Answer 1

3

Looks like AssignmentRuleHeader is case sensitive, Try changing it to assignmentRuleHeader.

Your code would then be:

sforce.connection.AssignmentRuleHeader = {}
sforce.connection.AssignmentRuleHeader.useDefaultRule = "true";

can also be written as:

sforce.connection.assignmentRuleHeader = { "useDefaultRule": "true" }

If this doesn't work, true instead of "true"

sforce.connection.assignmentRuleHeader = { "useDefaultRule": true }

Also you would not want window.location.reload(); at the end outside else, otherwise it would reload after the Status check alert.

1
  • Changing the AssignmentRuleHeader to assignmentRuleHeader and useDefaultRule= true without quotes did the trick. Thanks for the help! Commented Oct 13, 2017 at 12:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .