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
Karen Davis 1Karen Davis 1 

How do I add a true or false if statement to my javascript button?

I'm trying to add a condition to a javascript button that already works, but it's not working. If a checkbox called "Allow_new_exam_assessment__c" is true, then I want to execute the rest of the button script. If it's false, I want to generate an error message. Here's what I have - can someone tell me how it should be formatted? (

if('{!Treatment__c.Allow_new_exam_assessment__c}') { 
(this is where the rest of the code is - not putting it all here becuase it confuses things)

else 

alert("An exam assessment already exists for today or yesterday."); 
}
VineetKumarVineetKumar
Doing this '{!Treatment__c.Allow_new_exam_assessment__c}' will typecast your boolean value in string, and you can no longer use it directly in if condition, you might have to do something like below
var boolValue = '{!Treatment__c.Allow_new_exam_assessment__c}';
alert(boolValue);
if(boolValue != null && boolValue != '' && boolValue == 'true'){

}else{

}
Just put an alert above, to check the actual value.