1

My field is not getting updated for Owner Id on Case Object

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

var caseObj = new sforce.SObject("Case"); 
caseObj.Id = '{!Case.Id}'; 
var orgId = '{!Case.Original_Case_Owner__c}'; 
caseObj.Status = 'In Progress'; 
caseObj.RecordType = 'L2';

var records = sforce.connection.query("SELECT Id from User Where Name = '{!Case.Original_Case_Owner__c}'");
var records1 = records.getArray('records');
var userId = ''; 
for(var i=0;i<records1.length;i++)
{ userId = records1[i].Id; } 
caseObj.OwnerId= userId ; 

var result = sforce.connection.update([caseObj]); 
window.location.reload();
  • What is the data type of Original_Case_Owner__c, lookup to user or text? – PepeFloyd Jul 25 '14 at 12:33
  • It is a text field – user2703132 Jul 25 '14 at 12:43
4

Try this

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

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

var caseRecords = sforce.connection.query("SELECT Id from User Where Name = '{!Case.Original_Case_Owner__c}'");

var records = caseRecords.getArray("records");

caseObj.OwnerId = records[0].Id;
sforce.connection.update([caseObj]);

window.location.reload();
0

This code is working for me so I think you probably have a validation rule preventing the update on the case. It could also be a trigger or a workflow rule interfering with this. Can you take a look at the logs?

  • Sorry that was wrong . I have edited it. But it's still not working. – user2703132 Jul 25 '14 at 12:47
  • is the query returning any results? – PepeFloyd Jul 25 '14 at 12:48
  • I am not getting even error for the same. – user2703132 Jul 25 '14 at 12:49
  • The Query returning Id of the user in alert. But it is not getting updated. – user2703132 Jul 25 '14 at 12:49
  • I have updated my answer. – PepeFloyd Jul 25 '14 at 12:58

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.