The A-Z of FileMaker: G is for Get

G is for Get (functions)

The FileMaker calculation engine provides almost 300 built-in functions. Plug-ins and custom functions provide even more. The largest group of built-in functions is the Get group. FileMaker Pro 15  includes 116 Get functions and more are added each version. In the calculation engine, you can type “get” and press the return key to see all the Get functions:

Get functions

Inline help shows what each function will return.

The basic structure of a Get function is:

Get ( InformationName )

where the InformationName is the information returned by the function. Get functions do not have any parameters – they query the system and return information.

When was that?

Perhaps the most commonly used Get function is the one that returns today’s date:

Get ( CurrentDate )

The “current” date is provided by the machine where the calculation is evaluated  – that may be a desktop client, mobile device or server. To be consistent in the date used for a hosted solution, it may be better to use:

Get ( CurrentHostTimestamp )

While this will return both the date and time from the host, it can be explicitly coerced to the date:

GetAsDate ( Get ( CurrentHostTimestamp ) )

Alternatively, if the calculation returns a date result or is inserted in a date type field, then FileMaker will coerce the date for you.

Note

The GetAsDate function used above is not classified as a Get function. There are 9 GetAsType functions that coerce data to a specific data type. There are 14 other functions that also start with Get such as GetNthRecord and GetLayoutObjectAttribute.

Did you know?

The Get ( CurrentDate ) function has been known by different names in previous versions of FileMaker Pro. Most recently, it was Status (Current Date) and before that it was Today.

Other Get functions that return date and/or time are:

  • CurrentTime
  • CurrentTimestamp
  • CurrentTimeUTCMilliseconds
Timing of evaluation

As with all calculations, you should know when the expression will be evaluated and re-evaluated if necessary.

When using the Get ( CurrentDate ) function, a developer will usually expect it to be using the current date. For example, this is a calculation for the ageing of invoices that returns the number of days since the invoice was issued:

If ( InvoiceDate < Get ( CurrentDate ) ; 
     Get ( CurrentDate ) - InvoiceDate ; 
     0 )

If the calculation field is set up with default storage (stored result), the expression will be evaluated when the invoice date is entered or modified. However, if the solution is closed and re-opened the next day, the expression will not be re-evaluated using the new current date. For an invoice issued on a particular date, the age of the invoice may stay at zero (0) days forever.

To ensure that the expression is re-evaluated as needed. the developer should set the calculation storage to unstored by checking the option for “Do not store calculation results — recalculate when needed”:

calculation storage options
Set Storage Options… in the calculation dialog box
Querying security

There are a number of Get functions that return information about the current security level of the user. These include the account name, privilege set name and list of extended privileges. You can use these functions to control scripted operations while using proper FileMaker security setup.

Extended privileges are great for assigning privileges to multiple privilege sets. For example, in a medical system, a custom extended privilege to allow prescribing of drugs may be assigned to a number of privilege sets (chief MO, doctor, head nurse, psychiatrist) but not to others (nurse, administrator).

The function Get ( AccountExtendedPrivileges ) returns a list of enabled extended privileges for the logged in account privilege set. The following expression will check for the existence of the extended privilege canPrescribe in that list:

Length (
  FilterValues ( Get ( AccountExtendedPrivileges ) ; 
                                     "canPrescribe" )
       ) > 0

The expression can be used in an If or Else If script step to approve the running of the script steps that follow. Using a custom extended privilege in this way allows for quick and simple assignment (or revocation) of privileges to multiple privilege sets.

Query the device and network

Some Get functions provide information about the device and the network being used:

  • Device
  • HostIPAddress and HostName
  • NetworkProtocol and NetworkType
  • ConnectionAttributes and ConnectionState
  • PersistentID, SystemIPAddress and SystemNICAddress

You can identify and log devices and clients with these functions, as well as checking that the network is appropriate for connection.

Other Get functions check the client and host software:

  • ApplicationVersion, HostApplicationVersion, SystemVersion
Query the state of the solution

A number of Get functions allow the developer to check what is going on in the solution and act appropriately.

  • FoundCount, RecordNumber
  • RecordOpenState
  • LayoutName
  • WindowInfo (there are 14 of these such as WindowName)

For example, Get (FoundCount) is commonly used in scripting to determine what to do next. Different actions may be appropriate depending on if there are zero, one or many records found.

If a developer uses a consistent layout naming convention, Get ( LayoutName ) can be used to determine the context and the next action. In a script:

If [ PatternCount ( Get ( LayoutName ) ; "customer" ) ]
     # do this for customers
Else If [PatternCount ( Get ( LayoutName ) ; "invoice" ) ]
     # do this for invoices
Set a primary key

It is common to use a universally unique identifier (UUID) as a primary key value rather than a serial number. This is made easy by the use of the Get (UUID) function. This returns a unique 16-byte string such as:

35D390F0-3602-4CE0-8014-F4990A845934
Developer Tip

When creating a primary key field, use the Get (UUID) function in an auto-enter calculation. Remember to turn OFF “Do not replace existing value of field (if any)” to prevent duplicate UUIDs.

Set and get file locations

Get functions can be used to set storage locations for files when sending to PDF or exporting records, and for retrieving files for email attachment and other processes.

  • DesktopPath, DocumentsPath, TemporaryPath
  • FilePath, FileMakerPath, PreferencesPath

For example, a developer could define the path and file name for a PDF file as:

Get ( TemporaryPath ) & 
Cust::custCode & "_" & Invoice::invNo & ".PDF"

If the developer sets this to a variable, that variable can be used for defining the file attachment in a following Send Mail script step. Since the PDF is saved in the temporary path location, it is cleaned out at the end of the session.

And so much more…

As stated above, there are over 100 Get functions. Clearly there is not room in one blog post to cover even half of them.

As a FileMaker developer, you would be wise to spend time familiarising yourself with many of them including understanding exactly what each returns in what circumstances. Get functions will often return variable results based on where they are evaluated (FileMaker Pro, FileMaker Server, FileMaker Go, FileMaker WebDirect).

Did you know?

uLearnIT runs FileMaker classes. You will learn about Calculation and Summary Fields in the Get Started with FileMaker Pro 15 course.  Learn more about FileMaker classes.

5 Responses

  1. Yes no problem having both keys as text. Indexes for number fields are smaller but that will only come into play if you are considering millions of records. And then there are a few other things to think about too.

Leave a Reply

Your email address will not be published. Required fields are marked *