Brian Dunning's FileMaker Custom Functions

CorrectContext ( getFieldName_ )

CorrectContext is used to determine whether the current layout table name is the same as that of the field being tested

  Average rating: 4.1 (32 votes) Log in to vote

Malcolm Fitzgerald   Malcolm Fitzgerald
FM Studio

Share on Facebook Share on Twitter

  Sample input:
CorrectContext ( getFieldName ( table::field ) )
  Sample output:

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

This function provides a simple means to determine whether to proceed with script actions. Many script steps perform actions which depend on the current context. In the wrong context the script will fail, at least, and could do damage by adding, editing or deleting records. The Go To Related Record is particularly susceptible to failure and usually needs error trapping.

Dangerous Code:

Go to Related Record [ "children"; "formview" ]
Delete All Records [ no dialog ]

Problem: if there are no related records the GTRR script step does not go to the "formview" table and find no records. It stays where it is, in the parent table. The Delete All Records script step will then delete all Parent records in the found set.

Safer Code:

Go to Related Record [ "children"; "formview" ]
if ( CorrectContext ( getFieldName( children::id ) ) )
Delete All Records [ no dialog ]
end if

The CorrectContext function will accept any string and compare it to the current layout table name. However, hardcoding table names and field names is never safe. The safest and the most reliable way to use this function is to use the built-in function GetFieldName() to pass the name of the key field. GetFieldName uses a reference to the field, if the field name changes or the table name changes, the field reference is updated automatically. Nothing breaks, all your code continues to work.



Log in to post comments.


Note: these functions are not guaranteed or supported by Please contact the individual developer with any questions or problems.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 15 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth:

Under construction. Email me your wish list for improvements.