Build-On Tutorial:


Badges: Lesson 1

Event name badges

Lesson Overview

The objective for this lesson is to create a PDF that can be used for printing name badges for event attendees. To accomplish this, you will build a new layout and script to generate a PDF, and then add buttons to the Event Detail and Registration | Card layouts so that users may easily create badges for all attendees or a single attendee for an event.

Here is a sneak peek of what you will build:

Step 1 - Identify a template

There are a lot of choices on the market for printed template products such as name badges, labels, business cards, and more. Template printing is a common use case for FileMaker, and FileMaker Pro Advanced has many common templates already built in for manufacturers like Avery and DYMO. Even with so many choices available, however, there is a good chance that at some point you will need to work with a product for which there is no pre-built template in FileMaker Pro Advanced.

In this lesson you will learn how to create a template layout from scratch. You will work with the Avery 5392 Name Badge Insert template which is popular due to its compatibility with various badge holders (clip style, hanging style, etc.).

  1. Access the 5392 template from the Avery web site:
  2. Download the Microsoft Word template that Avery provides and note the page margins and column dimensions. You will use this information to build the new layout in FileMaker.
    1. Name badge: 4" wide x 3" tall
    2. Top margin: 1”
    3. Bottom margin: 0.57"
    4. Left margin: 0.34"
    5. Right margin: 0.31”

Step 2 - Create the layout

Next, you will create a FileMaker Pro Advanced layout that will be used to display the badges.

  1. Enter Layout mode using the Edit Layout button in the status toolbar.

    Note: You can also enter Layout mode using the View > Layout Mode menu item, or the keyboard shortcut Command-L (macOS) / Control-L (Windows).
  2. Open the New Layout/Report dialog by clicking the New Layout/Report button (or choose Layouts > New Layout/Report…)
  3. In the first screen of the New Layout/Report dialog:
    1. Set Show records from to REGISTRATION.
    2. Set the Layout Name to “Report | Attendee Badges - Avery 5392”.
    3. Select the Printer button.
    4. Select the Labels button.
    5. Click Continue.
  1. On the next screen of the New Layout/Report dialog, enter custom measurements to match those listed in Step 1.2 above:
    1. Select the Use custom measurements button.
    2. Set Labels across the page to 2.
    3. Set the Width to 4 inches.
    4. Set the Height to 3 inches.
    5. Check the Fixed page margins box.
    6. Set the Top margin to 1 inch.
    7. Set the Bottom margin to .57 inches.
    8. Set the Left margin to .34 inches.
    9. Set the Right margin to .31 inches.
    10. Click Next.
  1. On the Specify Label Contents screen of the New Layout/Report dialog:
    1. In the table occurrence drop-down menu for Available fields, choose registration_ATTENDEE.
    2. In the field list, add the Name_Last_First and Organization fields to the Label contents area as shown below.
    3. Click Finish.
  1. You will now be viewing the new layout in Layout mode. It will look similar to the image below.
  1. Enter Browse mode (View > Browse Mode, or Command-B (macOS) / Control-B (Windows)) to save and review your work.
  2. Open the Manage Layouts dialog (File > Manage > Layouts…).
    1. Move your newly created layout into the Print folder.
    2. Uncheck the Include in layout menus box.
    3. Close the Manage Layouts dialog.

Step 3 - Edit the layout

When you use the New Layout/Report dialog to walk through the process of creating a new label layout, it creates some settings by default that you will need to change.

  1. Return to Layout mode on the Report | Attendee Badges - Avery 5392 layout.
  2. The Avery 5392 template has six badges per page, arranged in three rows and two columns. FileMaker Pro Advanced guessed the number of rows that would fit on the page, and instead of three, it chose two and added a large Header part to compensate. You will need to delete the Header part now.

    To do so, select the Header part handle (as shown below) and press the Delete key.
  1. The vertical dashed lines indicate the position of the two columns across the page. Note that the right edge of the second column appears slightly to the right of the page edge. You will need to adjust the columns so that they fit exactly across the width of the layout.

    To accomplish this, click and hold your pointer on the vertical dashed line that separates the two columns, and then drag left slightly to resize the column width so that the second column edge lines up perfectly with the page edge.
  1. Open the Inspector using the View > Inspector menu item (you can also access it using keyboard shortcut Command-I (macOS) / Control-I (Windows)). Then activate the Appearance tab, which is used for setting fonts, font sizes, colors, and other types of visual formatting.
  1. Select the text object that contains the merge fields for the attendee name and organization and make the following changes to the formatting:
    1. In the Paragraph section of the Appearance tab, change the alignment for the entire text block to both vertically and horizontally centered.
    2. Double-click on the text object and select the first merge field <<registration_ATTENDEE::Name_First_Last>>. Set its text size to 24 pt and its text style to Bold.
    3. In the same text object, now select the second merge field <<registration_ATTENDEE::Name_First_Last>> and set its text size to 18 pt.
    4. Insert a carriage return between the two merge fields and set the text size of the blank line to 6 pt.
  1. Activate the Position tab of the Inspector, which is used for arranging and resizing objects.
  1. Select the text object again and set its Height to 182 pt.

    Note: If the units in the Position tab are currently displayed as in (inches) or cm (centimeters), click on a unit label repeatedly to toggle through the units until pt (points) is displayed.

    Your layout should now resemble the following image.
  1. Next, insert another merge field to display the event name at the bottom of the badge. Start by choosing Insert > Merge Field. In the resulting Specify Field dialog:
    1. In the table occurrence drop-down, choose registration_EVENT
    2. In the field list, choose Event_Name.
  1. Back on the layout, select the <<registration_EVENT::Event_Name>> merge field and use the Inspector to modify it:
    1. In the Position tab, set the Left position to 6 pt and the Top position to 161 pt.
    2. Set the Width to 272 pt and the Height to 46 pt
    3. On the Appearance tab, set the text size to 18 pt, text style to Bold, and text color to gray.
    4. Set the text block to be both vertically and horizontally centered.
  1. Enter Browse mode to save and review your work.

Step 4 - Create a script for printing the badges

Your next task is to write a script that will create a PDF displaying one or more attendee badges using the layout you created in Steps 2-3. You will create buttons that trigger this script in Step 5.

This script includes the option to print badges for all attendees for an event or for a single attendee. This is accomplished through the use of script parameters specified as name/value pairs. Your file includes a set of custom functions used for passing (#) and receiving (#Assign) named parameters. When the script receives a parameter named “id_event”, it knows to print badges for all attendees for the specified event; and when it receives a parameter named “id_registration”, it knows to print a single badge for the specified attendee registration.

From there, the script automatically creates a PDF file in the user’s temporary folder with a name that includes the current timestamp. The PDF is then automatically opened, and the user can choose to print it and/or save it to a known location.

  1. Open the Script Workspace by choosing the Scripts > Script Workspace… menu item or using the keyboard shortcut Shift-Command-S (macOS) / Shift-Control-S (Windows).
  2. Select and duplicate the Template Script.
    1. Name the new script “Report: Attendee Badges ( id_event ; id_registration )".
    2. Move the script to the REPORTS folder.

      Note: Any time you create a new script or copy an existing one, be sure to amend the comments at the top to fit your current script.
  1. Modify the script to add the steps highlighted below.

    See Steps 4-10 for further instructions on the Show Custom Dialog, New Window, Enter Find Mode, Sort Records, Print Setup, Set Variable, and Save Records as PDF steps.

Allow User Abort [ Off ]
Set Error Capture [ Off ]
Freeze Window

# load parameter(s)
Set Variable [ $parameter_parsing_ok; Value: #Assign ( Get ( ScriptParameter ) ) ]
If [ $parameter_parsing_ok = False ]
    # parameters could not be parsed, exit this script and report back
    Exit Script [ Result: "error" ]
Else If [ ( IsEmpty ( $id_event ) and IsEmpty ( $id_registration ) ) or ( not IsEmpty ( $id_event ) and not IsEmpty ( $id_registration ) ) ]
    # invalid parameter(s) passed
    Show Custom Dialog [ "Error"; "Invalid parameter(s) passed to script: " & Get ( ScriptName ) ]
    Exit Script [ Result: "error" ]
End If

# open report window offscreen
New Window [ Style: Document ; Name: “Report" ; Using layout: “Report | Attendee Badges - Avery 5392” (REGISTRATION) ; Height: 100 ; Width: 100 ; Top: -5000 ; Left: -5000 ]

# find registration records
Enter Find Mode [ Pause: Off ]
If [ not IsEmpty ( $id_event ) ]
    # find all active registrations for specified event
    Set Field [ REGISTRATION::ID_Event; "==" & $id_event ]
     Set Field [ REGISTRATION::Is_Registered; 1 ]
    # find specified registration
    Set Field [ REGISTRATION::ID; "==" & $id_registration ]
End If

Set Error Capture [ On ]
Perform Find [ ]
Set Error Capture [ Off ]
If [ $error ]
    Close Window [ Current Window ]
    If [ not IsEmpty ( $id_event ) and $error = 401 ]
        Show Custom Dialog [ “Alert" ; "There are currently no attendees for this event.” ]
        Show Custom Dialog [ “Error" ; If ( $error = 401 ; "The attendee could not be found." ; "FileMaker error: " & $error & "." ) & " Unable to generate this report.” ]
    End If
    Exit Script [ Result: $null ]
End If

# sort by attendee last name, first name
Sort Records [ Restore ; With dialog: Off ]

# create PDF in user's temporary folder and open it
Print Setup [ Restore ; With dialog: Off ]
Set Variable [ $file_path ; Value:
    Let ( [
        ~prefix = “file:” ;
        ~path = Get ( TemporaryPath ) ;
        ~event = registration_EVENT::Event_Name ;
        ~timestamp = _TimestampForFilename ;
        ~file_name = ~event & " Badges " & ~timestamp & ".pdf"
    ] ;
        ~prefix & ~path & ~file_name

Save Records as PDF [ With dialog: Off ; “$file_path” ; Automatically open ; Records being browsed ; Create directories: Off ]

# close report window
Close Window [ Current Window ]

Exit Script [ Result: $null ]

  1. For the three Show Custom Dialog script steps, double-click the script step (or click the gear icon to the right of the script step) to open the Show Custom Dialog Options dialog.
    1. In each instance, only the Default Button should be specified, all with the button text “OK”. The information for Button 2 should be removed.
    2. In the third instance of this step (see line number 49 in the image for Step 3 above), the custom dialog Message is calculated based on the particular error generated by the Perform Find script step that precedes it:
  1. For the New Window script step:.
    1. Set Window Style to Document.
    2. Set Window Name to “Report”.
    3. Set Layout to Report | Attendee Badges - Avery 5392.
    4. Set the layout Height and Width to 100 pt, and set the Top and Left positions to -5000 pt.
    5. Under Window Options, leave all the default settings in place.
  1. For the Enter Find Mode script step, make sure that Pause is set to Off (toggle this setting by clicking the text Off or On). Otherwise, the script will pause at this step and wait for user action.
  2. For the Sort Records script step, sort the registration list by attendee last name and first name.

    Since the attendee name fields are not in the Registration table, first select registration_ATTENDEE in the table occurrence drop-down, and then add the following fields to the sort order: Name_Last (ascending order), Name_First (ascending order).

    Finally, after closing the Sort Records dialog, set the With dialog option to Off (toggle this setting by clicking the text Off or On).
  1. For the Print Setup script step:
    1. Set Paper Size to US Letter.
    2. Set Orientation to Portrait.
  1. The second Set Variable script step sets a variable named $file_path which defines the path of the PDF that will later be created by the Save Records as PDF script step. Set $file_path to the following calculated value:

    Let ( [ ~prefix = "file:" ;
          ~path = Get ( TemporaryPath ) ;
          ~event = registration_EVENT::Event_Name ;
          ~timestamp = _TimestampForFilename ;
    ] ;
          ~prefix & ~path & ~file_name

    Note the following about this calculation:
    1. The Let function is used to separate the calculation into logical chunks and improve its readability.
    2. The file: prefix is used to indicate a relative, cross-platform file path.
    3. Get ( TemporaryPath ) returns the path of the temporary folder on the user’s device.
    4. _TimestampForFileName is a custom function which returns a formatted version of the current timestamp that can be safely used in a file name. This custom function has been added to your file.
  1. For the Save Records as PDF script step:
    1. Set With dialog to Off.
    2. Double-click on the script step (or click the gear icon and then Specify output file) to open the Specify Output File dialog. Type $file_path in the file path list, and check the Automatically open file box.
  1. Save the script and exit the Script Workspace.

Step 5 - Add buttons to run the reports

The final step is to create buttons to print the badges. You will start with adding a button to print badges for all attendees of an event.

  1. Enter Layout mode and navigate to the Attendees tab of the Event Detail layout.
  2. Duplicate the Manage Attendees button already on that layout.
  3. Double-click on the new button to open the Button Setup dialog, and make the following changes:
    1. Set the name of the button to “Print Badges”
    2. Set it to run the Report: Attendee Badges ( id_event ; id_registration ) script.
    3. Similar to the Manage Attendees button, the script parameter should be the following: # ( "id_event" ; EVENT::ID )
  1. Position the new button next to the Create Registration List button.
  1. Enter Browse mode to save and review your work.
  2. Next, create a button that will print a badge for a single attendee. Enter Layout mode again and navigate to the Registration | Card layout.
  3. Activate the Button Tool in the status toolbar.
  1. Using the Button tool, draw a button in the upper right corner of the layout. In the resulting Button Setup dialog:
    1. Set the name of the button to “Print Badge”.
    3. Set the script parameter to the following formula: # ( "id_registration" ; REGISTRATION::ID )
  1. Use the Inspector to finish configuring the button.
    1. With the Styles tab, assign the button the style btn Minimal.Blue.Next
    2. With the Position tab, set the button Width to 112 pt and Height to 44 pt.
    3. Position the button as shown below.
  1. Enter Browse mode to save and review your work.

Step 6 - Review your work

Your event attendee badge Build-On is now complete! Back in Browse mode, test your new report.

  1. From the Attendees tab of the Event Detail layout, click the Print Badges button and verify that the PDF displays badges for all registered event attendees.
  2. From the Attendees tab of the Event Detail layout, click on an attendee in the portal to open the Registration | Card layout displaying the attendee’s registration details. Then click the Print Badge button and verify that the PDF contains a badge for the current attendee.