1 2 Previous Next 19 Replies Latest reply on Apr 23, 2015 6:58 AM by enyko

    Help Creating a Saved Find the Date Field

    enyko

      Title

      Help Creating a Saved Find the Date Field

      Post

      Hi gang,

       

      Each week I create a find to look for all events for this upcoming weekend and simply save it as "This Weekend". I have it encompass Thursday through Sunday and it usually looks like for example;

       

      8/30/2012...9/2/2012

       

      Then I save it as "This Weekend" and I can use it all week. But each monday I have to create a new one. I'm just wondering i there is a way to create a "This Weekend" find that will always look at this Thursday through Sunday each week.

       

      Thanks!

        • 1. Re: Help Creating a Saved Find the Date Field
          philmodjunk

          Do it with a script.

          The script can use today's date or a date you enter in a global date field to construct the date range expression and use it as criteria in the find.

          Here's and example using today's date to compute the Thursday...Sunday date range and then uses it to perform the find:

          Set Variable [$Range ; value: Let ( [ T = Get ( CurrentDate ) ;
                                                                Dw = DayOfWeek ( T ) ;
                                                                Th = T - DW + 5 - 7 * ( Dw = 1 ) ; // calcs adjust when you perform script on a Sunday
                                                                Su = T - Dw + 7- 7 * ( Dw = 1 )
                                                              ] ;
                                                                 Th & "..." & Su
                                                           ) ] --> Do not type in the square bracket here. The script editor adds it for you.
          Enter Find Mode [] //clear the pause check box
          Set Field [YourTable::YourDateField ; $Range ]
          #You can add additional set field steps here if you need to specify other criteria in other fields for this find
          Set Error Capture [on]
          Perform Find []

          • 2. Re: Help Creating a Saved Find the Date Field
            enyko

            Thanks for the prompt response!

             

            I'm very novice to all this so forgive me. I think I have the script correct but got a bit lost when I'm in the Find Mode. Not sure where or how to do the remainder steps.

             

            Here is what I have so far;

             

            • 3. Re: Help Creating a Saved Find the Date Field
              philmodjunk

              And does it work? It looks correct in terms of how it should work, though you can delete some spaces to align the text on the subsequent lines so they line up in easier to read format.

              • 4. Re: Help Creating a Saved Find the Date Field
                enyko

                I don't know how to test it is the thing.

                 

                I've got the script complete as you see above but what do I search for after I click "Find"?

                 

                • 5. Re: Help Creating a Saved Find the Date Field
                  philmodjunk

                  But you don't have the script complete, you only have the first line.

                  You then need to add the other steps:

                  Enter Find Mode [] //clear the pause check box
                  Set Field [YourTable::YourDateField ; $Range ]
                  #You can add additional set field steps here if you need to specify other criteria in other fields for this find
                  Set Error Capture [on]
                  Perform Find []

                  • 6. Re: Help Creating a Saved Find the Date Field
                    philmodjunk

                    To add them, Click OK to close the specify calculation dialog and double click these other steps on the list found on the left.

                    • 7. Re: Help Creating a Saved Find the Date Field
                      enyko

                      Oh, I didn't know those were more steps.

                      I've added them but for the Set Field, there is no way for me to put in the ; $Range. (see attachment).

                      I ran the script without it and nothing happens. No error either.

                       

                       

                      • 8. Re: Help Creating a Saved Find the Date Field
                        philmodjunk

                        A commonly encountered issue with Set Field:

                        When Setting up Set Field, there are two Specify buttons that must be clicked. To get Set Field [Table::Field ; Expression], add set field to your script and click the first button (specify target field). Select Table::Field from the list of fields. Do not click the specify button next to the repetition box. Click OK to close this dialog box. Now click the lower specify button (calculated result) and create the expression to the right of the semicolon (;). Do not try to type in the semicolon.

                        • 9. Re: Help Creating a Saved Find the Date Field
                          enyko

                          Great! It works!

                           

                          2 follow ups;

                           

                          - How do I add another variable to check? For example I'd like to only see the "Booked" status (Field = Status; Value = "Booked").

                           

                          - Within the app, is there a way to add an icon in the toolbar to run this script simply with a click?

                           

                          Thanks!

                          • 10. Re: Help Creating a Saved Find the Date Field
                            philmodjunk

                            1) add another set field step to specify the additional criteria:

                            Set Field [Clients::Status ; "Booked"]

                            2) use the button tool while in layout mode to add a button to your layout. Select the Perform Script button action and select the script you've created as the script to be performed when you click the button.

                            • 11. Re: Help Creating a Saved Find the Date Field
                              enyko

                              WONDERFUL!

                               

                              Duh! About creating a button to run the script!

                               

                              Only problem I have now is to debug the script. When I run the script you wrote for me above I get 7 results. When I manually search for Event Date = 8/30/2012...9/2/2012 and Status = "Booked" I get 12 (which is the correct amount).

                               

                              Any thoughts?

                               

                              • 12. Re: Help Creating a Saved Find the Date Field
                                philmodjunk

                                Check to see if you are getting the same exact date range in your script as you used in your manual find.

                                After running the script, select Modify Find from the Records menu and see if the same date range you used is in the date field. It may need to be adjusted by one to include one more day in the date range.

                                • 13. Re: Help Creating a Saved Find the Date Field
                                  enyko

                                  Great! The script is pulling 8/30/2012...9/1/2012. One day short. But I'm sorry, not sure which one to adjust;

                                   

                                                                                        Th = T - DW + 5 - 7 * ( Dw = 1 ) ; // calcs adjust when you perform script on a Sunday

                                                                                        Su = T - Dw + 7- 7 * ( Dw = 1 )

                                   

                                  • 14. Re: Help Creating a Saved Find the Date Field
                                    philmodjunk

                                    My turn for a "DUH" moment!

                                    Su = T - Dw + 8 - 7 * ( Dw = 1 )

                                    1 2 Previous Next