Self is a function which returns the content of the object to which it is applied. Rather than explicitly naming a field, using the Self function means that an expression can be easily applied to another context with the same result.

Conditional formatting

One area where you will see the Self function being used is in conditional formatting. Let’s say you have a number field, outstanding amount, that you would like to display red when the amount is more than $1000. You can select the field on the layout and choose Format > Conditional…. Then you set the condition as Value is…greater than…1000.

conditional format value is

Setting the condition is easy – FileMaker Pro provides a lot of comparison operations in plain English. However, if you want to see how it works, change the Value is to Formula is. This exposes the expression being constructed for you:

conditional formula is

The Self function is used to reference the field to which the conditional formatting has been applied.

The great value in working this way is that if you duplicate the field object and specify another field (say, invoice total) then the conditional formatting will apply to the new field value. No changes required. Magic!

Field options

Another useful area for using the Self function is in field options – specifically in calculated auto-entry and calculated validation.

For example, if you have a field for State in an address, you may want to ensure that only uppercase letters are accepted. So you can use a auto-entered calculated value that replaces existing values:

Upper(Filter(Lower(Self);"abcdefghijklmnopqrstuvwxyz"))

Working from inside out, this expression starts with the lowercase version of any value in the field (using Self). It then filters it to just letters of the alphabet. Then it returns it as uppercase.

So if a user enters ”  n. s .w” into the State field, it will be corrected to “NSW”. And the beauty of this is that the expression can be copied and pasted into the auto-entered calculation for any field and it will just work.

Tip

Create a custom function called CleanUpperChar (text) which uses the same expression but with a text parameter instead of Self. Then when using the custom function, you enter CleanUpperChar (Self).

Where else can Self be used?

Self can also be used in Tooltips. This can be useful to be able to display the full contents of a field when the field object is too small.

field self tooltip

You can also construct a conditional tooltip based on the value of the field. If this mirrored the conditional formatting set, the tooltip could explain what the formatting means. For example, a red figure displays the tooltip “overdue”, while an orange figure displays “pending”, and a green figure displays “paid”.

Self can be used in Placeholder text but I cannot find any practical examples of that use. Self returns the content of the field but placeholder text only displays when the field is empty! If you have a use case, please let me know.

Where is Self not accepted?

Before you get too excited and want to use the Self function in everything to abstract your code, there are many areas where you cannot use it. FileMaker Pro will tell you where these are:

One example of this is when using Replace Field Contents with a calculated result. It seems to make sense that you could apply the above expression to a field and quickly clean up all existing content. But you cannot use the Self function. Fortunately, you can still do it – you just need to explicitly name the field.

Self cannot be used in an If statement when scripting. Again, it seems like it would make sense to be able to run a script in the context of the current object. But no go!

Consider yourself to have been Self-actualised!

Leave a Reply

Your email address will not be published.