Plug-in update example

The following example compares the version of an installed plug-in to the version located in a container field in the FileMaker Pro file and updates the plug-in, if necessary.

  1. In the custom app file, create a table named Plugin Update to store plug-in information.
  2. Define the following fields:
  3. Field name

    Field type

    Plugin Name

    text

    Required Plugin Version

    number

    Installed Plugin Version

    calculation (unstored). For example code, see Client plug-in version calculation below.

    Installed Plugin State

    calculation (unstored). For example code, see Client plug-in enabled state calculation below.

    Plugin File

    container

  4. Create a layout named Plugin Update Information and add to it the fields you defined in step 2.
  5. Create the following script and name it Install Plug-in:
    Copy
    Set Error Capture [On]
    Install Plug-In File [Plugin Update::Plug-in File]
    #
    #Deal with errors
    If [Get(LastError) ≠ 0]
        If [Get(LastError) = 3]
            Show Custom Dialog [Plugin Update::Plugin File & " could not be installed. Ensure Allow Solutions to Install Files is selected in the FileMaker Pro Plug-in preferences."]
        Else If [Get(LastError) = 1550]
            Show Custom Dialog [Plugin Update::Plugin File & " was installed but could not be initialized."]
        Else If [Get(LastError) = 1551]
            Show Custom Dialog [Plugin Update::Plugin File & " could not be installed."]
        Else
            Show Custom Dialog ["A general error " & Get(LastError) & " occured when installing " & Plugin Update::Plugin File]
        End If
    End If
  6. Create the following script and name it Check Plug-in Versions.
    Copy
    Go to Layout ["Plugin Update Information"]
    Go to Record/Request/page [First]
    Loop
        If [Plugin Update::Installed Plugin Version < Plugin Update::Required Plugin Version]
            #Plug-in needs to be either installed or updated.
            Perform script [Specified: From list ; "Install plug-in" ;
            Parameter: ]
        End If
        Go to Record/Request/page [Next; Exit after last: On]
    End Loop
  7. Create the following script and name it Check If Enabled:
    Copy
    Set Error Capture [On]
    Perform Find [Restore]
    #Find for "Enabled" in the Installed Plugin State field
    If[Get(FoundCount) < Get(TotalRecordCount)]
        Show Custom Dialog ["Some required plug-ins are not enabled. Ensure Allow Solutions to Install Files is selected in the FileMaker Pro Plug-in preferences."]
    End If
  8. Create a start-up script named Plugin Update Script that references the above scripts in order when the database opens:
    Copy
    Perform Script [Specified: From list ; "Check Plug-in Versions" ;
    Parameter: ]
    Perform Script [Specified: From list ; "Check If Enabled" ;
    Parameter: ]
    Go to Layout [original layout ; Animation: None ]

Client plug-in version calculation

Copy
Let (
    [
    PluginNamePosition = Position ( Get(InstalledFMPlugins); Plugin Name ; 1 ; 1 );
    PluginVersionStart = PluginNamePosition + Length( Plugin Name ) + 1;
    PluginVersionEnd = Position ( Get(InstalledFMPlugins); ";" ; PluginNamePosition ; 2 );
    PluginVersionLength = PluginVersionEnd - PluginVersionStart
    ];
    If ( PatternCount ( Get (InstalledFMPlugins) ; Plugin Name ) = 0 ; "" ; Middle ( Get(InstalledFMPlugins) ; PluginVersionStart ; PluginVersionLength ) )
)

Client plug-in enabled state calculation

Copy
Let (
    [
    PluginNamePosition = Position ( Get(InstalledFMPlugins); Plugin Name ; 1 ; 1 );
    PluginStateStart = Position ( Get(InstalledFMPlugins); ";" ; PluginNamePosition ; 2 ) + 1;
    PluginStateEnd = If ( Position ( Get(InstalledFMPlugins); "¶" ; PluginNamePosition ; 1 ) > 0; Position ( Get(InstalledFMPlugins); "¶" ; PluginNamePosition ; 1 ); Length( Get(InstalledFMPlugins) ) + 1 );
    PluginStateLength = PluginStateEnd - PluginStateStart
    ];
    If ( PatternCount ( Get (InstalledFMPlugins) ; Plugin Name ) = 0 ;
    "" ; Middle ( Get(InstalledFMPlugins) ; PluginStateStart ; PluginStateLength ) )
)

Notes 

  • For plug-ins to install, the Allow Solutions to Install Files option must be selected in the client's plug-in preferences. See Setting plug-in preferences.
  • If a plug-in has been disabled in the client's Plug-in preferences, it will install but will not be accessible until it is manually enabled by the user.
  • Only one plug-in can be stored in each container field, but you can view all plug-in information by creating multiple plug-in container fields on a single layout.