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
StaciStaci 

invoke assignment rule with javascript button

I'm making an escalate case button for our customers to use.  I need the funtionality to assign the case to a generic support queue if a checkbox is true, if not I need it to assign the case to the corresponding partner queue, which are set in the case assignment rules.  Is there a way to invoke the assignment rules in the javascript button? 
{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")} 

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


if('{!Case.CW_Advance_Support_Needed__c}' == true) 
{ 
caseObj.OwnerId = '00G30000001oUSL'; 
caseObj.Status = 'In Progress'; 

}else{ 


caseObj.CW_Advance_Support_Needed__c='True'; 
caseObj.Escalated_Date_Time__c=new Date().toJSON(); 

} 

if('{!Case.Incident_First_Response__c}'=='') 
{ 
caseObj.Incident_First_Response__c=new Date().toJSON(); 
} 

var result = sforce.connection.update([caseObj]); 
window.location.href=window.location.href;
Raj VakatiRaj Vakati
You need to set  assignmentRuleId rule id 
 
sforce.connection.header_name = {}
sforce.connection.header_name.header_option_name="value";
https://developer.salesforce.com/docs/atlas.en-us.ajax.meta/ajax/sforce_api_ajax_headers.htm?search_text=assignment
Sample code
 
{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")} 
sforce.connection.assignmentRuleId='IDOF ASSIGNENET RUE';
var caseObj = new sforce.SObject("Case"); 
caseObj.Id = '{!Case.Id}'; 


if('{!Case.CW_Advance_Support_Needed__c}' == true) 
{ 
caseObj.OwnerId = '00G30000001oUSL'; 
caseObj.Status = 'In Progress'; 

}else{ 


caseObj.CW_Advance_Support_Needed__c='True'; 
caseObj.Escalated_Date_Time__c=new Date().toJSON(); 

} 

if('{!Case.Incident_First_Response__c}'=='') 
{ 
caseObj.Incident_First_Response__c=new Date().toJSON(); 
} 

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

 
Raj VakatiRaj Vakati
try this 
https://salesforce.stackexchange.com/questions/93027/javascript-to-use-an-assignment-rules-on-a-case
{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")} 


 

sforce.connection.AssignmentRuleHeader = {}
sforce.connection.AssignmentRuleHeader.assignmentRuleId=ruleid ;



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


if('{!Case.CW_Advance_Support_Needed__c}' == true) 
{ 
caseObj.OwnerId = '00G30000001oUSL'; 
caseObj.Status = 'In Progress'; 

}else{ 


caseObj.CW_Advance_Support_Needed__c='True'; 
caseObj.Escalated_Date_Time__c=new Date().toJSON(); 

} 

if('{!Case.Incident_First_Response__c}'=='') 
{ 
caseObj.Incident_First_Response__c=new Date().toJSON(); 
} 

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

 
StaciStaci
@Raj Vakati neither of those suggestions worked

The If part is assigning the cases fine.  The else is not using the case assignment rules.  Any other suggestions?
Raj VakatiRaj Vakati
Check your assignment rules .. else conditions also conatins in assignment  rule or not
Rob KlemmRob Klemm
Neither of Raj's solutions worked for me either. What did work is the following:

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

I got this from https://salesforce.stackexchange.com/questions/195562/run-assignment-rule-from-javascript-button. As that post says, if the quotes around "true" don't work for you, try omitting them. I did not need to, but just in case...