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
Melissa GMelissa G 

Take Ownership Button (Not working for users)

Hi!

I have the following button on a page layout for my users that use cases. The button works great when I login (admin). However, when I login as the user nothing happens when the button is clicked. It appears the page refreshes but no information changes. Can anyone suggest why this is happening? Is it permission related? 

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

var updateRecord = new Array();
var myquery = "SELECT Id FROM Case WHERE Id = '{!Case.Id}' limit 1";

result = sforce.connection.query(myquery);
records = result.getArray("records");

if(records[0])
{
var update_Case = records[0];
update_Case.OwnerId = "{!$User.Id}";
update_Case.Status = "In Progress";
updateRecord.push(update_Case);
}

result = sforce.connection.update(updateRecord);
parent.location.href = parent.location.href;
@Karanraj@Karanraj
Make sure that user has API permission and also edit access to the record. Try to edit the same record without the custom button and see the result
Melissa GMelissa G
Good morning!

The user does have API access and access to the record. The record saves fine by changing ownership manully and saving the record. It's just the button that isn't working. 
@Karanraj@Karanraj
Can you try adding an alert message in the code to debug the return values for the user
{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}

var updateRecord = new Array();
var myquery = "SELECT Id FROM Case WHERE Id = '{!Case.Id}' limit 1";

result = sforce.connection.query(myquery);
records = result.getArray("records");
alert(records[0]);
if(records[0])
{
var update_Case = records[0];
update_Case.OwnerId = "{!$User.Id}";
update_Case.Status = "In Progress";
updateRecord.push(update_Case);
}
alert(updateRecord);
result = sforce.connection.update(updateRecord);
​alert(result);
parent.location.href = parent.location.href;

 
Melissa GMelissa G
Thank you very much.

It looks like it is conflicting with two validation rule (do not allow the users to reopen a closed case and case owner cannot be changed on a closed case). 

The cases are new and the validation rules should only be on closed cases. The code of the validation rules are below. Can you tell me if there is another user I should be excluding to get this to work (the validation rule should be working on the user I am logging in as, however) or of there is something else I can do to make both work together? Thanks!

AND( 
ISCHANGED(Status), 
ISPICKVAL(PRIORVALUE(Status), "Closed"),
Owner:User.Id <> LastModifiedBy.Id, 
$Profile.Name <> "System Administrator", 
$User.Id <> '00580000003xxYl'
)

AND(
   IsClosed,
   ISCHANGED(OwnerId),
    $Profile.Name <> "System Administrator",
   $User.Id <> '00580000003xxYl'
)

Thanks again so much!

Melissa