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
Jennifer BrownJennifer Brown 

Custom javascript button with confirm

I'm very new to javascript and looking for help on a button.  It's a custom "Take Ownership" button for cases but I'm looking to do two extra things:  1.  Pop up a confirm box if the owner is not null or a queue.  I'd also like to insert the owner's full name into the confirm box if possible.  (The intent here is to warn a user that someone has already taken ownership of this case if/when that happens.)  I'm missing a few things:

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

if(
 AND(
{!Case.OwnerFullName} <> "", 
{!Case.OwnerFullName} <> "Support Tier 1", 
{!Case.OwnerFullName} <> "Support Tier 2", 
{!Case.OwnerFullName} <> "Support Tier 3", 
{!Case.OwnerFullName} <> "Billing Queue", 
{!Case.OwnerFullName} <> "Customer Success", 
{!Case.OwnerFullName} <> "Customer Queue")){

if(confirm('This case is already assigned.  Are you sure you want to take ownership?')){ 

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 = "Active";
    updateRecord.push(update_Case);

result = sforce.connection.update(updateRecord);
parent.location.href = parent.location.href;
}
else {
alert("Error saving case: " + result[0]);
}
}
}
Jennifer BrownJennifer Brown
I think I figured out the owner part:  if(confirm('This case is already assigned to {!Case.OwnerFullName}.  Are you sure you want to take ownership?')){ 

But I'm getting this:    missing ) after argument list
Alain CabonAlain Cabon
Did you add the "AND(" with the button [Insert Selected Function]  ?

if ( {!AND(logical1,logical2,...)}

Alain