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();
  • What is the error/issue that you are getting when you execute this code? – Hemant Jain Oct 13 '17 at 10:24
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.

  • Changing the AssignmentRuleHeader to assignmentRuleHeader and useDefaultRule= true without quotes did the trick. Thanks for the help! – SFDC Learner Oct 13 '17 at 12:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.