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

MBS FileMaker Plugin Example Databases

WebHook Listener

All examples are included with download of MBS FileMaker Plugin.

WebHook Listener.fmp12

Overview
Tables1
Relationships0
Layouts1
Scripts4
Value Lists0
Custom Functions0
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: Setup
OnLastWindowCloseScript: Cleanup
OnWindowOpenOff
OnWindowCloseOff
OnFileAVPlayerChangeOff
Thumbnail Settings
Generate ThumbnailsOn; Temporary

 

Tables

Table Name
Statistics
Occurrences in Relationship Graph
Listener
7 fields defined, 1 record
Listener

Fields

Table Name: Listener - 7 Fields
Field NameTypeOptionsCommentsOn LayoutsIn RelationshipsIn ScriptsIn Value Lists
PrimaryKeyNormal, TextAuto-Enter:
  • Context table: Listener
    Calculation: Get( UUID )
Validation:
  • Only during data entry
  • Not empty
  • Unique
  • Strict validation
Storage:
  • Repetitions: 1
  • Indexing: Minimal
  • Automatically create indexes as needed
  • Index Language: Unicode Raw
Unique identifier of each record in this table
          CreationTimestampNormal, TimestampAuto-Enter:
          • Creation timestamp
          Validation:
          • Only during data entry
          • Strict data type: 4 digit year
          • Not empty
          • Strict validation
          Storage:
          • Repetitions: 1
          • Indexing: None
          • Automatically create indexes as needed
          • Index Language: German
          Date and time each record was created
                  CreatedByNormal, TextAuto-Enter:
                  • Creation account name
                  Validation:
                  • Only during data entry
                  • Not empty
                  • Strict validation
                  Storage:
                  • Repetitions: 1
                  • Indexing: None
                  • Automatically create indexes as needed
                  • Index Language: German
                  Account name of the user who created each record
                          ModificationTimestampNormal, TimestampAuto-Enter:
                          • Modification timestamp
                          Validation:
                          • Only during data entry
                          • Strict data type: 4 digit year
                          • Not empty
                          • Strict validation
                          Storage:
                          • Repetitions: 1
                          • Indexing: None
                          • Automatically create indexes as needed
                          • Index Language: German
                          Date and time each record was last modified
                                  ModifiedByNormal, TextAuto-Enter:
                                  • Modification account name
                                  Validation:
                                  • Only during data entry
                                  • Not empty
                                  • Strict validation
                                  Storage:
                                  • Repetitions: 1
                                  • Indexing: None
                                  • Automatically create indexes as needed
                                  • Index Language: German
                                  Account name of the user who last modified each record
                                          My IPNormal, TextAuto-Enter:
                                          • Allow editing
                                          Validation:
                                          • Only during data entry
                                          Storage:
                                          • Repetitions: 1
                                          • Indexing: None
                                          • Automatically create indexes as needed
                                          • Index Language: German
                                              PortNormal, NumberAuto-Enter:
                                              • Allow editing
                                              Validation:
                                              • Only during data entry
                                              Storage:
                                              • Repetitions: 1
                                              • Indexing: None
                                              • Automatically create indexes as needed
                                              • Index Language: German

                                                  Layout Objects: Listener

                                                  Regular Fields

                                                  Field Name: Listener::My IP
                                                  Field PropertiesCoordinatesField FormatField BehaviorQuick Find
                                                  • Top: 114 pt
                                                  • Left: 138 pt
                                                  • Bottom: 145 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: Listener::Port
                                                  Field PropertiesCoordinatesField FormatField BehaviorQuick Find
                                                  • Top: 149 pt
                                                  • Left: 138 pt
                                                  • Bottom: 180 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

                                                  Setup
                                                  Cleanup
                                                  WebHookReceived
                                                  Test Script

                                                  Next Script: [Cleanup]
                                                  Script NameSetup
                                                  Run script with full access privilegesOff
                                                  Include In MenuYes
                                                  Layouts that use this script
                                                    Scripts that use this script
                                                      Script Definition
                                                      Script Steps
                                                      • If [ Length( $$WebHooks ) > 0 ]
                                                      • Set Variable [ $r; Value:MBS("WebHook.Release"; $$WebHooks) ]
                                                      • Set Variable [ $$WebHooks; Value:"" ]
                                                      • End If
                                                      • If [ IsEmpty ( $$WebHooks ) ]
                                                      • Set Variable [ $$WebHooks; Value:MBS("WebHook.Create") ]
                                                      • #we need to keep connection open
                                                      • Set Variable [ $r; Value:MBS("WebHook.SetMode"; $$WebHooks; 1) ]
                                                      • Set Variable [ $r; Value:MBS("WebHook.SetAutoAnswer"; $$WebHooks; "") ]
                                                      • #listen on random port
                                                      • Set Variable [ $r; Value:MBS("WebHook.Listen"; $$WebHooks; 0) ]
                                                      • #set script to run
                                                      • Set Variable [ $r; Value:MBS("WebHook.SetScript"; $$WebHooks; Get(FileName); "WebHookReceived") ]
                                                      • #now show IP and Port
                                                      • Set Field [ Listener::Port; MBS( "WebHook.GetPort"; $$WebHooks ) ]
                                                      • Set Field [ Listener::My IP; Get(SystemIPAddress) ]
                                                      • Commit Records/Requests [ No dialog ]
                                                      • 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: [Setup]Next Script: [WebHookReceived]
                                                              Script NameCleanup
                                                              Run script with full access privilegesOff
                                                              Include In MenuYes
                                                              Layouts that use this script
                                                                Scripts that use this script
                                                                  Script Definition
                                                                  Script Steps
                                                                  • If [ not IsEmpty ( $$WebHooks ) ]
                                                                  • Set Variable [ $r; Value:MBS("WebHook.Release"; $$WebHooks) ]
                                                                  • Set Variable [ $$WebHooks; Value:"" ]
                                                                  • #now show IP and Port
                                                                  • Set Field [ Listener::Port; "" ]
                                                                  • Set Field [ Listener::My IP; "" ]
                                                                  • Commit Records/Requests [ No dialog ]
                                                                  • 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: [Cleanup]Next Script: [Test Script]
                                                                          Script NameWebHookReceived
                                                                          Run script with full access privilegesOff
                                                                          Include In MenuNo
                                                                          Layouts that use this script
                                                                            Scripts that use this script
                                                                              Script Definition
                                                                              Script Steps
                                                                              • #Which request triggered this?
                                                                              • Set Variable [ $WebRequest; Value:Get(ScriptParameter) ]
                                                                              • #Parse parameters from the URL
                                                                              • Set Variable [ $URLComponents; Value:MBS( "WebRequest.URLComponents"; $WebRequest ) ]
                                                                              • Set Variable [ $Parameters; Value:JSONGetElement ( $URLComponents ; "Parameters" ) ]
                                                                              • Set Variable [ $ScriptName; Value:JSONGetElement ( $Parameters ; "ScriptName" ) ]
                                                                              • Set Variable [ $FileName; Value:JSONGetElement ( $Parameters ; "FileName" ) ]
                                                                              • Set Variable [ $Wait; Value:JSONGetElement ( $Parameters ; "Wait" ) ]
                                                                              • #we can move several Megabytes of Data in this parameter
                                                                              • Set Variable [ $Parameter; Value:MBS( "WebRequest.GetBody"; $WebRequest; "UTF-8") ]
                                                                              • Set Variable [ $Result; Value:"" ]
                                                                              • If [ $Wait ]
                                                                              • // Set Variable [ $ScriptToRun; Value:If ( Length ( $FileName ) > 0 ; $FileName & "::" & $ScriptName; $ScriptName ) ]
                                                                              • Perform Script [ By name; $ScriptName; Parameter: $Parameter ]
                                                                              • Set Variable [ $Result; Value:Get(ScriptResult) ]
                                                                              • Else
                                                                              • Set Variable [ $Result; Value:MBS("FM.RunScript"; $FileName; $ScriptName; $Parameter) ]
                                                                              • #empty answer
                                                                              • Set Variable [ $text; Value:"HTTP/1.1 200 OK¶Server: MyServer 1.0¶Connection: close¶Content-Length: 0¶¶" ]
                                                                              • Set Variable [ $text; Value:MBS( "Text.ReplaceNewline"; $Text; 3 ) ]
                                                                              • Set Variable [ $r; Value:MBS("WebRequest.Send"; $WebRequest; $text; "UTF-8") ]
                                                                              • Set Variable [ $r; Value:MBS("WebRequest.Release"; $WebRequest) ]
                                                                              • Exit Script [ ]
                                                                              • End If
                                                                              • #send HTTP Response here
                                                                              • #get length of answer
                                                                              • Set Variable [ $body; Value:MBS( "Text.EncodeToHex"; $Result; "UTF-8") ]
                                                                              • Set Variable [ $ContentLength; Value:Length($body) / 2 ]
                                                                              • #build header
                                                                              • Set Variable [ $text; Value:"HTTP/1.1 200 OK¶Server: MyServer 1.0¶Connection: close¶Content-Type: plain/text¶Content-Length: " & $contentLength & "¶¶" ]
                                                                              • Set Variable [ $text; Value:MBS( "Text.ReplaceNewline"; $Text; 3 ) ]
                                                                              • Set Variable [ $r; Value:MBS("WebRequest.Send"; $WebRequest; $text & $result; "UTF-8") ]
                                                                              • #give time to send answer
                                                                              • Pause/Resume Script [ Duration (seconds): ,5 ]
                                                                              • Set Variable [ $r; Value:MBS("WebRequest.Release"; $WebRequest) ]
                                                                              • Exit Script [ ]
                                                                              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: [WebHookReceived]
                                                                                            Script NameTest Script
                                                                                            Run script with full access privilegesOff
                                                                                            Include In MenuYes
                                                                                            Layouts that use this script
                                                                                              Scripts that use this script
                                                                                                Script Definition
                                                                                                Script Steps
                                                                                                • #This is the text script to call
                                                                                                • Show Custom Dialog [ Title: "Test Script called"; Message: Get(ScriptParameter); Default Button: “OK”, Commit: “Yes” ]
                                                                                                • Exit Script [ Result: "Greetings from Listener" ]
                                                                                                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

                                                                                                              Download example: WebHook Listener

                                                                                                              Used functions: