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();
2
  • What is the data type of Original_Case_Owner__c, lookup to user or text?
    – PepeFloyd
    Jul 25, 2014 at 12:33
  • It is a text field Jul 25, 2014 at 12:43

2 Answers 2

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?

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

You must log in to answer this question.

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