Friday, September 30, 2011

Filemaker Pro 11: Create boolean checkboxes

How to create a checkbox field in FileMaker Pro. 
For some odd reason, FileMaker Pro does not have a "native" boolean checkbox field. Instead of simply dropping a simple checkbox on to a form (called a layout…in FM Pro),  you have to strictly follow a roundabout procedure to what is a dodle in virtually all other development systems.   

However, in the English version of FM Pro 11,  one of the sample databases; "People Management" contains checkboxes in the "issues" section for two fields: 
These are labeled: 
Is Legal Involved? 
Is HR Involved?  

And the field names in the data table are: 

Flag Legal
Flag HR 

So, for example,  to create a checkbox in the employee record to determine if the person preferred "Smoking",  (for what....hotel rooms perhaps?)  You can do the following: 

1. In the Value list Editor create a value list named "1" 
Source = Custom Values
Values = "1" 
FileMaker Pro 11 Value Lists 

2. Go to Manage Databases. In your data table,  define the field name for the checkbox field. 
Give it a field type = Number 
The sample shows two fields,  Flag HR and Flag Legal (these field names have spaces in them, which is something I would never do.) 

Database fields for "Issues" table

I created a new field "Smoking" in the Employee table.  Set the type to  "Number" 


OK….so now the table fields have been defined, and lookup value has been defined. Now, what remains is displaying the field in your layout.    

3. On the layout Add  the new field and choose the new Smoking field within the Employee table 



This starts out as a text field… looking like this: 


4. In the Inspector,  edit the properties of the field to change the field type to 
"Checkbox Set"  and change the value list to "1".   This will make the field look like this: 


5.  Adjust the size of the field to cover up the "1" which makes the field look normal. 


6. Now when you switch to browse you get: 

  
This appears to give a value of "1" when checked,  and I'm a assuming, a 'null' or 0 when unchecked.   Anyway, in a query for people who smoke, you'd have to look for smoking =1 
I think.  Not intuitive.   

I'd appreciate comments and corrections from the FM experts.   


5 comments:

DominicusB said...

Thanks for this tutorial. It seems so simple when you outline the steps this easy.
Tried all morning to find a solution for check-boxes, but this was the first that made sense.
Now I have it working

Vic said...

I'm a new FileMaker user (v12) so excuse my ignorance if this is incorrect:

By using a value list the field defined turns true for ALL records if selected for any record. At least that's what happened to me?

Great tip for a checkbox since the tutorial addresses exactly what I wanted to do but the value has to be segregated to individual records.

What am I missing?

Larry Keyes said...

hmm...not sure.... do you have a global or local variable floating around of the same name that is assigned to the field?

Daniel A. Shockley said...

When you "uncheck" the 1, it then leaves the field empty (not zero, but blank). IF you want your field to be explicitly 1 or 0, you can go into Manage Database, select the field, choose Options -> Auto-Enter, Calculated Value (UN-check "Do not replace existing value of field"), and then enter this:
If( not Self; 0; 1 )
Then, be SURE to uncheck "Do not evaluate if all referenced fields are empty" because you do want it to evaluate when empty (that's the whole point *grin*).

Vic: It does sound like you have that field defined as a Global (look under Manage Database, Options, Storage - global should be unchecked if want a different value for each record).

Nirgal said...

Just an FYI - FMPro, in the context of number fields, will recognize the text values of "Yes" and "True" as equal to 1, and the text values of "No" and "False" as 0, in case it's easier to mentally parse yes/no or true/false rather than 1/0.