1

i'm trying to create a javascript button to update some values on a case record and then push it through the assignment rules. the following code updates the fields i want but doesn't push it through the rules, what am i missing??

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

var caseObj = new sforce.SObject("Case");
caseObj.RecordTypeId = '01280000000Q9uk';
caseObj.Reason = 'Transfer from Billing';
var result = sforce.connection.update([caseObj]);

assignObj = new sforce.SObject("AssignmentRuleHeader");
assignObj.assignmentRuleId = '01Q80000000Gcdr';
caseObj.Id = '{!Case.Id}';
var result = sforce.connection.update([caseObj]);

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

2 Answers 2

1

You forgot to assign the header to the connection:

sforce.connection.AssignmentRuleHeader = { "assignmentRuleId": "01Q80000000Gcdr" };

See this topic for details on how to use headers.

1
  • Thanks! Still not going through the rules,what am i missing?{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")} var caseObj = new sforce.SObject("Case"); caseObj.RecordTypeId = '01280000000Q9uk'; caseObj.Reason = 'Transfer from Billing'; assignObj = new sforce.SObject("AssignmentRuleHeader"); assignObj.assignmentRuleId = '01Q80000000Gcdr'; caseObj.Id = '{!Case.Id}'; sforce.connection.AssignmentRuleHeader = { "assignmentRuleId": "01Q80000000Gcdr" }; var result = sforce.connection.update([caseObj]); if (result[0].success=='false') { alert(result[0].errors.message); } else { location.reload(); } Nov 17, 2015 at 19:47
1

In addition to @sfdcfox answer which is the essence of your problem, curiously, your follow-on issue is that the documentation is in disagreement with the real property name for the alleged AssignmentRuleHeader.

sforce.connection.AssignmentRuleHeader =        // uppercase 'A' does not work
    { "assignmentRuleId": "01Q80000000Gcdr" };  

sforce.connection.assignmentRuleHeader =        // lowercase 'a' does work
    { "assignmentRuleId": "01Q80000000Gcdr" };  

Verified at V37.0 using an Onclick Javascript button.

If you inspect the sforce.connection object prior to setting the headers, you can see the properties all start with a lowercase letter. To say this is confusing given that the doc refers to them in initial Caps is why this community stays in business.

enter image description here

You must log in to answer this question.

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