FileMaker 9 Tip#5: Using the Self Function

One of the least talked about features of FileMaker 9 is a new calculation called `Self`. Although the primary purpose of this function is to facilitate the Conditional Formatting feature (which can perform calculations on such unnamed items as text objects and buttons), `Self` comes in handy in lots of common situations.

The `Self` function is simple in concept: it returns the value of whatever object it lives in. For instance, if you put `Self` in a validation calculation, it will return the value in the field being validated.

This might seem a little…well..pointless. After all, there’s another way to get at that field’s value in a calculation: put the field name in the calculation.

The advantage of `Self` is subtle. Since you don’t have to refer to the field explicitly by name, you can easily copy and paste the formula somewhere else without the need to edit it. How often have you added the exact same validation calculation to several different fields? Before `Self` you had to adjust it in each field to refer to the correct value. With `Self`, the same formula — unchanged — works in each place.

Self has one more capability that’s a little less useful. When you use Conditional Formatting (Format -> Conditional in layout mode), you can perform calculations on *text objects* and *buttons*. For example, if you apply conditional formatting to a text object, you can use `Self` in the condition formula. In that case, `Self` returns the contents of the text object itself. More specifically, it returns the *browse mode* contents. If the text object contains merge fields or other special symbols, the result of `Self` includes the actual replacement data.

I’m not entirely sure what you’d ever *do* with that ability (and I’ve spent far too much time trying to think of something). If you find a cool use for it, let us know in the comments 🙂

Leave a Comment

11 thoughts on “FileMaker 9 Tip#5: Using the Self Function

  1. I just made some navigation buttons that have the same name as the layout. Then you format it with “self = get (layoutname).” It’s now bold and a different color when it appears on its own layout. Not terribly dramatic, but dead easy.

  2. @susan: I always knew you were a genius 🙂 That’s an awesome idea…it is such a nuisance to change out your navigation buttons on each layout. I love it.

    Geoff

  3. Since the Self function will return the contents of a field that it refers to, you can use tooltips to display the entire contents of a field.

    Take the case of a list where there is limited space for a field. When a user hovers their mouse over the field, a tooltip appears that displays the entire field contents.

    This was done in the past by defining the tooltip with the field name. Not any more – set the tooltip to Self. Then duplicate the field (with its tooltip), specify the field for the duplicate and the tooltip will display the contents of the new field.

    Now all that is just great. But what about existing fields? Set all the tooltips individually? No way. Select ALL the fields you want to add these tooltips to, right-clic, select Set Tooltip… and specify Self. All fields will display their individual field contents. Cool or what?

  4. You can use Self to highlight the column heading of a list layout to indicate sorting.

    1. pass a Script Parameter “self” to the sort script;
    … i.e., you’re passing the text of the button…
    2. in the script set $$sortorder to the param;
    3. conditionally format the button you clicked with self = $$sortorder

    You can extend this to include an up or down triangle for ascending/descending sort, using a dingbat font that you hide/show by changing its text color to match the background or not. However, this method seems to require individually naming each object, which is kind of a bummer. I.e. you can nicely use conditional formatting for this part, but not the Self function.

  5. @tom: That is a very cool technique. I am positive I’ll be using it myself. I already use a single script and global variables to keep track of sort order so I can swap ascending/descending, so I can apply your idea to get visual feedback for my users with just some conditional formatting. Awesome 🙂

  6. Tom Fitch’s idea sounds good, but fm9 doesn’t like Self as a script parameter. I’ve got a solution going where the menu buttons are text which changes colour conditionally if it matches the current layout name. With this I can have one set of menu buttons which I copy across to all my layouts, but I still have to enter a different script parameter for each button. They also have the same tooltip calculation.

  7. Great Script Parameter, BUT be very careful that all users are running FM 9 + or you will get errors. ? FM 8.5 doesn’t support the SELF parameter. Another great function is Upper(Self) as a lookup to ensure the data is all upper format.

  8. Not sure if this was mentioned…

    I use Self() all the time in the “Auto-Enter” -> “Calculate value” (with Do not replace existing value turned off) to strip pasted in text of it’s formating: TextFormatRemove ( Self )

    … especially email address fields where people tend to paste bright blue and underlined formated test.

    You can create custom calcs to do other things upon data entry. The example I’ve seen before is to re-format a phone number to your standard convention.

  9. FileMaker 10 Advanced:

    I would like to have a script, triggered by leaving/saving an entry field, that figures out itself from which field it was triggered, if the field’s value was empty, and if so, sets the field value to a certain default value – to avoid having to define that script a dozen times, one for each field.

    Whatever I tried, FM won’t accept the Self() function in that place – neither as a script parameter not in the formula to get/set the field value.

    I’d like to know if there IS a way – that I’m obviously missing – to achive this using the Self() function, and if so, how to use it correctly.

    Many thanks in advance for any hints on this.

    Pete