5 Replies Latest reply on Aug 11, 2017 1:54 PM by thatoneitguy

    Using Custom Dialogue for Logic Input


      Hello FileMaker community! My job kind of threw this project at me and this is my first foray into FileMaker, so please be gentle as I may be a little bit slow. I'm familiar with both coding and database management, but FileMaker has been a bit different than what I am used to seeing.


      Anyway, here is my project:

      I am designing a simple receptionist program that allows guests to sign in using an iPad with FileMaker Go connected to a database on FileMaker Pro. The main menu features two buttons: "Sign In" and "Sign Out". When "Sign In" is pressed, the attached script (Get Name) runs. As you can see in the script, the visitor is encouraged to type in their first and last name in a Custom Dialog. These are then used as Find criteria to determine if this person has visited us before, and a different Go To Layout step is used depending on the result of this Find. I am aware this is not a good way to determine whether this is a new visitor or not, names not necessarily being unique and all, but it will work for my company's purposes and has been fairly easy to implement in the timeframe they've given me. The rest of the project works more or less as intended, except for the initial sign-in.


      The problems are twofold:

      1. If the user hits the "Cancel" button on the Custom Dialog, the rest of the script executes anyway, leaving the user in the "New Visitor" Layout with nothing pre-populated. Is there a way to execute the lower portion of the script (lines 11 onward) only if the "Ok" button is pressed in the Custom Dialog, such as a "Break Out" command? Could the Get Name script be split into two so that the second portion executes on press of the "Ok" button? With my limited familiarity with the program, and even moreso Custom Dialogs, I'm not even sure if using a Custom Dialog is the best way to go about this part of the process. I am thinking there might be a way to capture the button selection from the Custom Dialog and feed that into the lower part of the script using a Global field, but I'm not sure.
      2. The Else portion of the If-Else block is never executing, even if a repeat user types in their name exactly as they did before. I suspect this is because the LastError field may be populated by some other area of the project, or previous runs. Is there a way to clear this field before using it as logical input? Is this even how the LastError field works?


      Thank you for your help. I apologize for having to attach the script as I have. I cannot seem to figure out how to export or copy the script text to place here...

        • 1. Re: Using Custom Dialogue for Logic Input

          For show custom dialog--not necessarily the best option, you can use the Get ( LastMessageChoice ) function call to detect which button was tapped by the user to close the dialog. This returns the number of the button tapped.


          I will usually write the code like this:


          Show Custom Dialog....

          If [ Get ( Last (Messagechoice ) = 1 // OK ]

             Do what is needed if OK is tapped.


          //OK is a comment that I add reminding myself which label was given to button 1. It saves time when you review such code a month later.


          Your scripted find does not look like it will work as written. As stored find criteria can't access the values of fields--such as those used in your custom dialog.


          I'd use some text fields with global storage specified in the custom dialog with a script like this:


          Show Custom Dialog....

          If [ Get ( Last (Messagechoice ) = 1 // OK ]

              Enter Find Mode [pause:off]

              Set Field [ YourTable::FirstNameField ; YourTable::GlobalFirstNameField ]

              Set Field [YourTable::LastNameField ; YourTable::GlobalLastnameField ]

              Set Error Capture [on]
              Perform Find [ ]


              #Cancel was tapped


          For more about scripted finds:

          See the first part of this discussion for a number of examples:

          Scripted Find Examples

          1 of 1 people found this helpful
          • 2. Re: Using Custom Dialogue for Logic Input

            Your first one is easy - look into the Get(LastMessageChoice) function. On line 10 of your script, insert an if statement which calls that function, follow with the "Exit Script" step, and close the if statement. It's a very simple process, but if the user clicks the "Cancel" button on the dialog box, the LastMessageChoice will return a value of 2 (the default for the cancel button), which will be caught by the if statement causing the script to execute the exit script step.Capture.PNG


            Your second question can be a little more complex. You're not using the "Get(LastError)" function incorrectly, but it's very broad. ANY error will cause the script to follow the IF portion of the statement, never executing the else like you stated. If you have FileMaker Pro Advanced, step through the script and see if what error(s) are being returned. If you don't own FMPA, set a dialog box after line 13 of your script to return the value of "Get(LastError)". That will help you diagnose what is happening and what errors your encountering.

            1 of 1 people found this helpful
            • 3. Re: Using Custom Dialogue for Logic Input

              As a completely different approach, you might look at the "auto-complete value lists II" example found in the following teaching file. It demonstrates an auto-complete enabled value list of names where you enter part of a person's name and the list filters down to just those that match. It includes code that detects and handles two contacts with the same exact name and offers to create a new record for a contact if the name entered doesn't match to any contact in the system.


              Adventures in FileMaking #2-enhanced value selection

              1 of 1 people found this helpful
              • 4. Re: Using Custom Dialogue for Logic Input

                I think I was using the shorthand Find command since I'd read it in some other help articles. I had thought it set the two fields you mentioned (Variables table is the globals) in its dialog, but it may not have. Either way, it appears to be working correctly now! Using the GetLastMessageChoice also appears to be parsing user input on the dialog correctly as well.

                • 5. Re: Using Custom Dialogue for Logic Input

                  Unfortunate that using step-through is only a feature of the Advanced version of the program but ah well. Thank you for suggesting using the dialogs as error checking. Not sure why I hadn't thought of that. Shows how long it has been since I wrote any significant code without a more advanced IDE...