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
andremsalgadoandremsalgado 

Making a button to "Take a Case"

Gentlemen,

 

I created a button with a script similar function "Change Owner" that I found in internet, the difference is that it only takes the case when this case is in a queue. Blocking I take cases from other users.

 

The problem is that when a user who does not have full access to function if this function does not perform.

 

Could anyone help me in this problem? Maybe run this function in adminitrador mode?

 

Thank you in advance.

 

Regards,

André Salgado

 

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

var records = {!GETRECORDIDS($ObjectType.Case)};
var userId = "{!$User.Id}";

var updateRecords = [];
var updateRecordsOther = [];
var updateRecordsSelf= [];
var queryResults = sforce.connection.retrieve("CaseNumber, Id, OwnerId,Owner.Type", "Case", records);

for (var caseIndex=0;caseIndex<queryResults.length;caseIndex++)
{
	var caseObj = queryResults[caseIndex];
				  
	var CaseNum = caseObj.CaseNumber;
	var caseID= caseObj .Id;
	var ExistingOwner = caseObj.OwnerId;

	if (ExistingOwner == '00GU0000000P2gSMAS') 
	{
	   
	 //Otherwise accept it
	var caseUpdate = new sforce.SObject("Case");

	caseUpdate.Id = caseID;
	caseUpdate.OwnerId = userId;
	updateRecords.push(caseUpdate);
	}
	else
	{
		if ('{!JSENCODE($User.Id )}' != '{!JSENCODE( Case.OwnerId )}') 
		{
            updateRecordsOther.push(1);
			
		}else
		{
            updateRecordsSelf.push(1);			
	   }
   }
}

if (updateRecordsOther.length>0) 
{	
	alert('Its already have an owner');
}

if (updateRecordsSelf.length>0) 
{
	
}

if (updateRecords.length>0) 
{
	sforce.connection.update(updateRecords);
	
	alert( updateRecords.length + ' Case to: ' + '{!JSENCODE($User.FirstName )}' + ' ' + '{!JSENCODE( $User.LastName )}');
	window.location.reload();
}