Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

MBS FileMaker Plugin Example Databases

JavaScript Custom Functions

All examples are included with download of MBS FileMaker Plugin.

JavaScript Custom Functions.fmp12

Overview
Tables2
Relationships1
Layouts2
Scripts5
Value Lists0
Custom Functions3
Custom Menus24
File Options
Default custom menu set[Standard FileMaker Menus]
When opening file
Minimum allowed version12.0
Login usingAccount Name; Account= Admin
Allow user to save passwordOff
Require iOS passcodeOff
Switch to layoutOff
Hide all toolbarsOff
Script triggers
OnFirstWindowOpenScript: Start Script
OnLastWindowCloseOff
OnWindowOpenOff
OnWindowCloseOff
OnFileAVPlayerChangeOff
Thumbnail Settings
Generate ThumbnailsOn; Temporary

 

Tables

Table Name
Statistics
Occurrences in Relationship Graph
JavaScriptCustomFunctions
7 fields defined, 5 records
JavaScriptCustomFunctions
JavaScriptCustomFunctionParameters
5 fields defined, 9 records
JavaScriptCustomFunctionParameters

Fields

Table Name: JavaScriptCustomFunctions - 7 Fields
Field NameTypeOptionsCommentsOn LayoutsIn RelationshipsIn ScriptsIn Value Lists
IDNormal, NumberAuto-Enter:
  • Allow editing
  • Serial: Generate: On creation, Next value: 6, Increment: 1
Validation:
  • Only during data entry
  • Unique
Storage:
  • Repetitions: 1
  • Indexing: All
  • Index Language: German
        NameNormal, TextAuto-Enter:
        • Allow editing
        Validation:
        • Only during data entry
        Storage:
        • Repetitions: 1
        • Indexing: None
        • Automatically create indexes as needed
        • Index Language: German
            DeclarationNormal, TextAuto-Enter: Validation:
            • Only during data entry
            Storage:
            • Repetitions: 1
            • Indexing: None
            • Automatically create indexes as needed
            • Index Language: German
                  DescriptionNormal, TextAuto-Enter:
                  • Allow editing
                  Validation:
                  • Only during data entry
                  Storage:
                  • Repetitions: 1
                  • Indexing: None
                  • Automatically create indexes as needed
                  • Index Language: German
                        BodyNormal, TextAuto-Enter:
                        • Allow editing
                        Validation:
                        • Only during data entry
                        Storage:
                        • Repetitions: 1
                        • Indexing: None
                        • Automatically create indexes as needed
                        • Index Language: German
                            ResultNormal, TextAuto-Enter:
                            • Allow editing
                            Validation:
                            • Only during data entry
                            Storage:
                            • Repetitions: 1
                            • Indexing: None
                            • Automatically create indexes as needed
                            • Index Language: German
                                SampleCallNormal, TextAuto-Enter: Validation:
                                • Only during data entry
                                Storage:
                                • Repetitions: 1
                                • Indexing: None
                                • Automatically create indexes as needed
                                • Index Language: German

                                      Table Name: JavaScriptCustomFunctionParameters - 5 Fields
                                      Field NameTypeOptionsCommentsOn LayoutsIn RelationshipsIn ScriptsIn Value Lists
                                      IDNormal, NumberAuto-Enter:
                                      • Allow editing
                                      • Serial: Generate: On creation, Next value: 10, Increment: 1
                                      Validation:
                                      • Only during data entry
                                      • Unique
                                      Storage:
                                      • Repetitions: 1
                                      • Indexing: All
                                      • Index Language: German
                                          NameNormal, TextAuto-Enter:
                                          • Allow editing
                                          Validation:
                                          • Only during data entry
                                          Storage:
                                          • Repetitions: 1
                                          • Indexing: None
                                          • Automatically create indexes as needed
                                          • Index Language: German
                                              DescriptionNormal, TextAuto-Enter:
                                              • Allow editing
                                              Validation:
                                              • Only during data entry
                                              Storage:
                                              • Repetitions: 1
                                              • Indexing: None
                                              • Automatically create indexes as needed
                                              • Index Language: German
                                                    FunctionIDNormal, NumberAuto-Enter:
                                                    • Allow editing
                                                    Validation:
                                                    • Only during data entry
                                                    Storage:
                                                    • Repetitions: 1
                                                    • Indexing: All
                                                    • Index Language: German
                                                        ValueNormal, TextAuto-Enter:
                                                        • Allow editing
                                                        Validation:
                                                        • Only during data entry
                                                        Storage:
                                                        • Repetitions: 1
                                                        • Indexing: None
                                                        • Automatically create indexes as needed
                                                        • Index Language: German

                                                            Layout Objects: JavaScriptCustomFunctions

                                                            Regular Fields

                                                            Field Name: JavaScriptCustomFunctions::Name
                                                            Field PropertiesCoordinatesField FormatField BehaviorQuick Find
                                                            • Top: 126 pt
                                                            • Left: 137 pt
                                                            • Bottom: 157 pt
                                                            • Right: 971 pt
                                                            • Anchoring: Left and Right, Top
                                                            Field Format:
                                                            • Edit Box
                                                            Field Behavior:
                                                            • Allow field to be entered: In Find mode, In Browse mode
                                                            • Touch keyboard type: Default for Data Type
                                                            • Go to next field using: Tab key
                                                            Yes

                                                            Field Name: JavaScriptCustomFunctions::Declaration
                                                            Field PropertiesCoordinatesField FormatField BehaviorQuick Find
                                                            • Top: 161 pt
                                                            • Left: 137 pt
                                                            • Bottom: 192 pt
                                                            • Right: 971 pt
                                                            • Anchoring: Left and Right, Top
                                                            Field Format:
                                                            • Edit Box
                                                            Field Behavior:
                                                            • Allow field to be entered: In Find mode, In Browse mode
                                                            • Touch keyboard type: Default for Data Type
                                                            • Go to next field using: Tab key
                                                            Yes

                                                            Field Name: JavaScriptCustomFunctions::Description
                                                            Field PropertiesCoordinatesField FormatField BehaviorQuick Find
                                                            • Top: 196 pt
                                                            • Left: 137 pt
                                                            • Bottom: 227 pt
                                                            • Right: 971 pt
                                                            • Anchoring: Left and Right, Top
                                                            Field Format:
                                                            • Edit Box
                                                            Field Behavior:
                                                            • Allow field to be entered: In Find mode, In Browse mode
                                                            • Touch keyboard type: Default for Data Type
                                                            • Go to next field using: Tab key
                                                            Yes

                                                            Field Name: JavaScriptCustomFunctions::Body
                                                            Field PropertiesCoordinatesField FormatField BehaviorQuick Find
                                                            • Top: 451 pt
                                                            • Left: 138 pt
                                                            • Bottom: 757 pt
                                                            • Right: 968 pt
                                                            • Anchoring: Left and Right, Top and Bottom
                                                            Field Format:
                                                            • Edit Box
                                                            Field Behavior:
                                                            • Allow field to be entered: In Find mode, In Browse mode
                                                            • Touch keyboard type: Default for Data Type
                                                            • Go to next field using: Tab key
                                                            Yes

                                                            Field Name: JavaScriptCustomFunctionParameters::Name
                                                            Field PropertiesCoordinatesField FormatField BehaviorQuick Find
                                                            • Top: 250 pt
                                                            • Left: 145 pt
                                                            • Bottom: 281 pt
                                                            • Right: 394 pt
                                                            • Anchoring: Left, Top
                                                            Field Format:
                                                            • Edit Box
                                                            Field Behavior:
                                                            • Allow field to be entered: In Find mode, In Browse mode
                                                            • Touch keyboard type: Default for Data Type
                                                            • Go to next field using: Tab key
                                                            Yes

                                                            Field Name: JavaScriptCustomFunctionParameters::Description
                                                            Field PropertiesCoordinatesField FormatField BehaviorQuick Find
                                                            • Top: 250 pt
                                                            • Left: 398 pt
                                                            • Bottom: 281 pt
                                                            • Right: 706 pt
                                                            • Anchoring: Left, Top
                                                            Field Format:
                                                            • Edit Box
                                                            Field Behavior:
                                                            • Allow field to be entered: In Find mode, In Browse mode
                                                            • Touch keyboard type: Default for Data Type
                                                            • Go to next field using: Tab key
                                                            Yes

                                                            Field Name: JavaScriptCustomFunctionParameters::Value
                                                            Field PropertiesCoordinatesField FormatField BehaviorQuick Find
                                                            • Top: 250 pt
                                                            • Left: 711 pt
                                                            • Bottom: 281 pt
                                                            • Right: 960 pt
                                                            • Anchoring: Left, Top
                                                            Field Format:
                                                            • Edit Box
                                                            Field Behavior:
                                                            • Allow field to be entered: In Find mode, In Browse mode
                                                            • Touch keyboard type: Default for Data Type
                                                            • Go to next field using: Tab key
                                                            Yes

                                                            Field Name: JavaScriptCustomFunctions::Result
                                                            Field PropertiesCoordinatesField FormatField BehaviorQuick Find
                                                            • Top: 770 pt
                                                            • Left: 325 pt
                                                            • Bottom: 801 pt
                                                            • Right: 780 pt
                                                            • Anchoring: Left and Right, Bottom
                                                            Field Format:
                                                            • Edit Box
                                                            Field Behavior:
                                                            • Allow field to be entered: In Find mode, In Browse mode
                                                            • Touch keyboard type: Default for Data Type
                                                            • Go to next field using: Tab key
                                                            Yes

                                                            Field Name: JavaScriptCustomFunctions::SampleCall
                                                            Field PropertiesCoordinatesField FormatField BehaviorQuick Find
                                                            • Top: 810 pt
                                                            • Left: 138 pt
                                                            • Bottom: 841 pt
                                                            • Right: 968 pt
                                                            • Anchoring: Left and Right, Bottom
                                                            Field Format:
                                                            • Edit Box
                                                            Field Behavior:
                                                            • Allow field to be entered: In Find mode, In Browse mode
                                                            • Touch keyboard type: Default for Data Type
                                                            • Go to next field using: Tab key
                                                            Yes

                                                            Buttons

                                                            Button PropertiesCoordinatesScript/Script Step
                                                              Type:
                                                            • Text: Register and Try
                                                            • Top: 766 pt
                                                            • Left: 788 pt
                                                            • Bottom: 806 pt
                                                            • Right: 968 pt
                                                            • Anchoring: Right, Bottom
                                                            Perform Script [ “Test Function” ]

                                                            Scripts:


                                                            Button PropertiesCoordinatesScript/Script Step
                                                              Type:
                                                            • Text: Register Function
                                                            • Top: 766 pt
                                                            • Left: 137 pt
                                                            • Bottom: 806 pt
                                                            • Right: 317 pt
                                                            • Anchoring: Left, Bottom
                                                            Perform Script [ “Register Function” ]

                                                            Scripts:


                                                            Portals

                                                            Portal PropertiesCoordinatesFieldsOptions
                                                            • Top: 245 pt
                                                            • Left: 140 pt
                                                            • Bottom: 442 pt
                                                            • Right: 968 pt
                                                            • Anchoring: Left, Top
                                                            Field Objects
                                                            • Sort records: Off
                                                            • Filter calculation: None
                                                            • Initial Row: 1
                                                            • Number of Rows: 5
                                                            • Allow deletion of portal records

                                                            Layout Objects: JavaScriptCustomFunctionParameters

                                                            Regular Fields

                                                            Field Name: JavaScriptCustomFunctionParameters::ID
                                                            Field PropertiesCoordinatesField FormatField BehaviorQuick Find
                                                            • Top: 114 pt
                                                            • Left: 138 pt
                                                            • Bottom: 145 pt
                                                            • Right: 217 pt
                                                            • Anchoring: Left, Top
                                                            Field Format:
                                                            • Edit Box
                                                            Field Behavior:
                                                            • Allow field to be entered: In Find mode, In Browse mode
                                                            • Touch keyboard type: Default for Data Type
                                                            • Go to next field using: Tab key
                                                            Yes

                                                            Field Name: JavaScriptCustomFunctionParameters::Name
                                                            Field PropertiesCoordinatesField FormatField BehaviorQuick Find
                                                            • Top: 155 pt
                                                            • Left: 138 pt
                                                            • Bottom: 186 pt
                                                            • Right: 391 pt
                                                            • Anchoring: Left, Top
                                                            Field Format:
                                                            • Edit Box
                                                            Field Behavior:
                                                            • Allow field to be entered: In Find mode, In Browse mode
                                                            • Touch keyboard type: Default for Data Type
                                                            • Go to next field using: Tab key
                                                            Yes

                                                            Field Name: JavaScriptCustomFunctionParameters::Description
                                                            Field PropertiesCoordinatesField FormatField BehaviorQuick Find
                                                            • Top: 190 pt
                                                            • Left: 138 pt
                                                            • Bottom: 221 pt
                                                            • Right: 391 pt
                                                            • Anchoring: Left, Top
                                                            Field Format:
                                                            • Edit Box
                                                            Field Behavior:
                                                            • Allow field to be entered: In Find mode, In Browse mode
                                                            • Touch keyboard type: Default for Data Type
                                                            • Go to next field using: Tab key
                                                            Yes

                                                            Field Name: JavaScriptCustomFunctionParameters::FunctionID
                                                            Field PropertiesCoordinatesField FormatField BehaviorQuick Find
                                                            • Top: 225 pt
                                                            • Left: 138 pt
                                                            • Bottom: 256 pt
                                                            • Right: 217 pt
                                                            • Anchoring: Left, Top
                                                            Field Format:
                                                            • Edit Box
                                                            Field Behavior:
                                                            • Allow field to be entered: In Find mode, In Browse mode
                                                            • Touch keyboard type: Default for Data Type
                                                            • Go to next field using: Tab key
                                                            Yes

                                                            Field Name: JavaScriptCustomFunctionParameters::Value
                                                            Field PropertiesCoordinatesField FormatField BehaviorQuick Find
                                                            • Top: 260 pt
                                                            • Left: 138 pt
                                                            • Bottom: 291 pt
                                                            • Right: 391 pt
                                                            • Anchoring: Left, Top
                                                            Field Format:
                                                            • Edit Box
                                                            Field Behavior:
                                                            • Allow field to be entered: In Find mode, In Browse mode
                                                            • Touch keyboard type: Default for Data Type
                                                            • Go to next field using: Tab key
                                                            Yes

                                                            Script Hierarchy

                                                            Start Script
                                                            RefreshDeclaration
                                                            Register Function
                                                            Test Function
                                                            Try it

                                                            Next Script: [RefreshDeclaration]
                                                            Script NameStart Script
                                                            Run script with full access privilegesOff
                                                            Include In MenuYes
                                                            Layouts that use this script
                                                              Scripts that use this script
                                                                Script Definition
                                                                Script Steps
                                                                • #Start script to create JavaScript environment named "js"
                                                                • Set Variable [ $JS; Value:MBS("JS.New"; "js" ) ]
                                                                • If [ MBS("IsError") ]
                                                                • Show Custom Dialog [ Title: "Failed to initialize JavaScript engine."; Message: $JS; Default Button: “OK”, Commit: “Yes” ]
                                                                • Set Variable [ $JS; Value:"" ]
                                                                • Exit Script [ ]
                                                                • End If
                                                                • #register all functions
                                                                • Go to Layout [ “JavaScriptCustomFunctions” (JavaScriptCustomFunctions) ]
                                                                • #you could do a search here to only find the functions you need
                                                                • Go to Record/Request/Page [ First ]
                                                                • Loop
                                                                • Perform Script [ “Register Function” ]
                                                                • Go to Record/Request/Page [ Next; Exit after last ]
                                                                • End Loop
                                                                • Go to Record/Request/Page [ First ]
                                                                • #clear result fields
                                                                • Replace Field Contents [ JavaScriptCustomFunctions::Result; Replace with calculation: "" ] [ No dialog ]
                                                                Fields used in this script
                                                                Scripts used in this script
                                                                Layouts used in this script
                                                                Tables used in this script
                                                                Table occurrences used by this script
                                                                Custom Functions used by this script
                                                                  Custom menu set used by this script

                                                                    Previous Script: [Start Script]Next Script: [Register Function]
                                                                    Script NameRefreshDeclaration
                                                                    Run script with full access privilegesOff
                                                                    Include In MenuYes
                                                                    Layouts that use this script
                                                                      Scripts that use this script
                                                                        Script Definition
                                                                        Script Steps
                                                                        • #assign value to itself to trigger calculation for declaration field
                                                                        • Set Field [ JavaScriptCustomFunctions::Name; JavaScriptCustomFunctions::Name ]
                                                                        Fields used in this script
                                                                        Scripts used in this script
                                                                          Layouts used in this script
                                                                            Tables used in this script
                                                                            Table occurrences used by this script
                                                                            Custom Functions used by this script
                                                                              Custom menu set used by this script

                                                                                Previous Script: [RefreshDeclaration]Next Script: [Test Function]
                                                                                Script NameRegister Function
                                                                                Run script with full access privilegesOff
                                                                                Include In MenuYes
                                                                                Layouts that use this script
                                                                                Scripts that use this script
                                                                                Script Definition
                                                                                Script Steps
                                                                                • #Register one function. Replacing older one with same name
                                                                                • Set Variable [ $r; Value:MBS( "JS.AddFunction"; "js"; JavaScriptCustomFunctions::Name; "function(" & Substitute(List ( JavaScriptCustomFunctionParameters::Name ); ¶; ", ") & ") { " & ¶ & JavaScriptCustomFunctions::Body & ¶ & " }" ) ]
                                                                                • If [ MBS("IsError") ]
                                                                                • Show Custom Dialog [ Title: "Failed to add function."; Message: $r; Default Button: “OK”, Commit: “Yes” ]
                                                                                • End If
                                                                                Fields used in this script
                                                                                Scripts used in this script
                                                                                  Layouts used in this script
                                                                                    Tables used in this script
                                                                                    Table occurrences used by this script
                                                                                    Custom Functions used by this script
                                                                                      Custom menu set used by this script

                                                                                        Previous Script: [Register Function]Next Script: [Try it]
                                                                                        Script NameTest Function
                                                                                        Run script with full access privilegesOff
                                                                                        Include In MenuYes
                                                                                        Layouts that use this script
                                                                                        Scripts that use this script
                                                                                          Script Definition
                                                                                          Script Steps
                                                                                          • #Register function
                                                                                          • Set Variable [ $r; Value:MBS( "JS.AddFunction"; "js"; JavaScriptCustomFunctions::Name; "function(" & Substitute(List ( JavaScriptCustomFunctionParameters::Name ); ¶; ", ") & ") { " & ¶ & JavaScriptCustomFunctions::Body & ¶ & " }" ) ]
                                                                                          • If [ MBS("IsError") ]
                                                                                          • Show Custom Dialog [ Title: "Failed to add function."; Message: $r; Default Button: “OK”, Commit: “Yes” ]
                                                                                          • Else
                                                                                          • Set Variable [ $ParameterCount; Value:ValueCount ( List ( JavaScriptCustomFunctionParameters::ID ) ) ]
                                                                                          • Set Variable [ $r; Value:MBS( "JS.CallFunctionValues"; "js"; JavaScriptCustomFunctions::Name; If($ParameterCount ≥ 1; GetNthRecord ( JavaScriptCustomFunctionParameters::Value ; 1)); If($ParameterCount ≥ 2; GetNthRecord ( JavaScriptCustomFunctionParameters::Value ; 2)); If($ParameterCount ≥ 3; GetNthRecord ( JavaScriptCustomFunctionParameters::Value ; 3)); If($ParameterCount ≥ 4; GetNthRecord ( JavaScriptCustomFunctionParameters::Value ; 4)); If($ParameterCount ≥ 5; GetNthRecord ( JavaScriptCustomFunctionParameters::Value ; 5)); If($ParameterCount ≥ 6; GetNthRecord ( JavaScriptCustomFunctionParameters::Value ; 6)); If($ParameterCount ≥ 7; GetNthRecord ( JavaScriptCustomFunctionParameters::Value ; 7)); If($ParameterCount ≥ 8; GetNthRecord ( JavaScriptCustomFunctionParameters::Value ; 8)); If($ParameterCount ≥ 9; GetNthRecord ( JavaScriptCustomFunctionParameters::Value ; 9)) ) ]
                                                                                          • Set Field [ JavaScriptCustomFunctions::Result; $r ]
                                                                                          • If [ MBS("ISError") ]
                                                                                          • Show Custom Dialog [ Title: "Result"; Message: $r; Default Button: “OK”, Commit: “Yes” ]
                                                                                          • End If
                                                                                          • End If
                                                                                          Fields used in this script
                                                                                          Scripts used in this script
                                                                                            Layouts used in this script
                                                                                              Tables used in this script
                                                                                              Table occurrences used by this script
                                                                                              Custom Functions used by this script
                                                                                                Custom menu set used by this script

                                                                                                  Previous Script: [Test Function]
                                                                                                  Script NameTry it
                                                                                                  Run script with full access privilegesOff
                                                                                                  Include In MenuYes
                                                                                                  Layouts that use this script
                                                                                                    Scripts that use this script
                                                                                                      Script Definition
                                                                                                      Script Steps
                                                                                                      • #just call with passing values and the name of our JavaScript Environment
                                                                                                      • Set Variable [ $r; Value:MBS( "JS.CallFunctionValues"; "js"; "Concat"; "Hello"; "World" ) ]
                                                                                                      • #Alternative pass JSON, so strings get quoted
                                                                                                      • Set Variable [ $r; Value:MBS( "JS.CallFunction"; "js"; "Concat"; "\"Hello\""; "\"World\"" ) ]
                                                                                                      • #Best use JS.CF to call through directly
                                                                                                      • Set Variable [ $r; Value:MBS( "JS.CF"; "Concat"; "Hello"; "World" ) ]
                                                                                                      • Show Custom Dialog [ Title: "Result"; Message: $r; Default Button: “OK”, Commit: “Yes” ]
                                                                                                      Fields used in this script
                                                                                                        Scripts used in this script
                                                                                                          Layouts used in this script
                                                                                                            Tables used in this script
                                                                                                              Table occurrences used by this script
                                                                                                                Custom Functions used by this script
                                                                                                                  Custom menu set used by this script

                                                                                                                    Custom Functions

                                                                                                                    Function NameParametersAvailabilityDefinitionIn Field DefinitionsIn Scripts
                                                                                                                    JSFunctionNameAll accountsMBS("JS.CallFunctionValues"; "js"; FunctionName)
                                                                                                                      JS1FunctionName;Value1All accountsMBS("JS.CallFunctionValues"; "js"; FunctionName; Value1)
                                                                                                                        JS2FunctionName;Value1;Value2All accountsMBS("JS.CallFunctionValues"; "js"; FunctionName; Value1; Value2)

                                                                                                                          Custom Menu Sets

                                                                                                                          Menu SetsMenusIn ScriptsIn LayoutsComments
                                                                                                                          [Standard FileMaker Menus]
                                                                                                                          • All Standard Menus

                                                                                                                          Download example: JavaScript Custom Functions

                                                                                                                          Used functions: