0

I am creating a custom button that will update the Status field on the Case object to "Resolved". Before the field is updated, I would like to first check if the field already is set to "Resolved". If so, then I would alert the user. If not, the field update would carry on. I have the below code in place but I am receiving the error "ReferenceError: Case is not defined" when the button is selected. I believe I'm just missing a minor snippet of syntax - any help resolving this would be appreciated!

/* 
* Configuration: 
* Create new Detail Page Button for Account w/ Behavior "Execute JavaScript" 
* and Content Source "OnClick JavaScript" then add to page layout. 
*/ 
{!REQUIRESCRIPT("/soap/ajax/27.0/connection.js")} 

try { 

var url = parent.location.href; 
var updateRecords = []; 
var update_Case = new sforce.SObject("Case__c"); 
update_Case.Id = "{!Case.Id}";  
update_Case.Status = 'Resolved'; 
updateRecords.push(update_Case); 

if ({!Case.Status}) { 

alert("The Case Status is already resolved") 

} 

else { 

result = sforce.connection.update(updateRecords); 

if ( !result[0].getBoolean("success") ) { 

var errors = result[0].errors; 
var errorMessages = errors.message; 
alert( errorMessages ); // display all validation errors 

} 

else { 

alert("Request has been submitted"); 
parent.location.href = url; 

} 

} 


} 

catch (e) { 

alert (e); 

}

Error

2

You just need to wrap your field in quotes so that JavaScript properly interprets the merge output as a String:

if ("{!Case.Status}" === "Resolved") { 
   alert("The Case Status is already resolved") 
} 

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.