5 Replies Latest reply on Dec 14, 2012 8:27 AM by philmodjunk

    Prompt for date selection in Script

    SandyHaaf

      Title

      Prompt for date selection in Script

      Post


           How do you make a script prompt the user to enter data for find?  What I want to do is have the user select a date range for the layout (report) to run on.  Basically, I want the user to be able to select the date range that they want the report run on. 

            

           At the moment my script basically does this:

           Enter Browse Mode[]

           Go To Layout["Power Summary by day"(Wind Data)]

           Sort Records[Restore;No dialog]

            

            

           Also, how do you put that date range on the report.  So, I'd like the title of the report to include the date range that they selected.

           Power Generated Report for 1/1/12 - 12/31/12 or Power Generated Report for 10/1/12-10/31/12

            

           Thanks,

           Sandy

        • 1. Re: Prompt for date selection in Script
          philmodjunk

               Define two global date fields, Globals::gDate1 and Globals::gDate2

               Put them on a layout where the user can enter the start and stop dates of this date range. If you want, a script can use New Window to present a small floating window into which they can enter these dates.

               Then use this script to perform your find:

               Go to Layout ["Power Summary by day"(Wind Data)]
               enter Find mode[]---> clear the pause check box
               Set Field [WindData::YourDateField ; Globals::gDate1 & "..." & Globals::gDate2 ] --->gdate1 and gDate2 must have global storage specified in field options
               Set Error Capture [on]---> keeps "no records found" dialog from interrupting script if no records are found
               Perform Find []
               Sort Records[Restore;No dialog]

               Here's a window I pop up for similar purposes in one of my databases:

          • 2. Re: Prompt for date selection in Script
            SandyHaaf

                 How do you create the global date fields?  OK, I found the Global Field option when setting up a new field.  I'm wondering if I should add the global field to my main table or if I should simply create a separate table for them? 

            • 3. Re: Prompt for date selection in Script
              philmodjunk

                   Open Manage | database | Fields.

                   Select the table where you want to define this field in the table drop down. Fields with global storage will be accessible from any script and layout in your file no matter which table you select. I often use a separate table just for these type of global fields to make it a bit easier to keep track of them.

                   Enter the field name and click create. Click the options button. Click the storage tab. Click the check box for global storage.

                   You may also want to look up global fields in FileMaker help to learn more about them.

              • 4. Re: Prompt for date selection in Script
                SandyHaaf

                     How do you have the global layout open without any values?  Can I delete them upon entering or something like that?

                • 5. Re: Prompt for date selection in Script
                  philmodjunk

                       That depends on your system and what you want to do. Yes, your script can clear the global values, but consider the fact that if you want to give the user a "modify find" capability, you might not always want to clear them.

                       And in a database hosted over the network, values entered by the user into a global field are not retained, so in that case, each time the user opens the file, they start with empty fields. (I make sure that the fields are empty before moving the file to the server.)

                       In my own solutions, I use a script that uses New Window to display a window like what I uploaded and a script parameter is checked to see if the fields should be cleared or not before opening the new window. That way, a find button passes "clear" as a script parameter and a modify find button does not--both performing the same script.