9 Replies Latest reply on Mar 1, 2013 4:24 PM by Svetlana

    A script to display limited records

    Svetlana

      Title

      A script to display limited records

      Post

           Hi everyone,

           I am trying to write a script for a button to display records with a date entered in a date field that is 14 days away from current date. I am a total newbie so I'd really appreciate any help I can get.

           Thank you :)

        • 1. Re: A script to display limited records
          philmodjunk

               I will read that as records with a date that is 14 days in the future.

               Get ( currentDate ) + 14

               will compute a date 14 days in the future.

               That could be part of a find in a date range, with an inequality operator or just by itself depending on what results you want from your find.

               Here is a thread with multiple scripted find examples you can look at to see how this can work: Scripted Find Examples

          • 2. Re: A script to display limited records
            Svetlana

                 Thank you so much for the quick response! I'll use that as a guideline and if I have further questions I'll let you know.

            • 3. Re: A script to display limited records
              Svetlana

                   All that worked perfectly, thanks again so much!

                   I was having an issue with modifying the script to display records with a date field whose date is  ≤ 14 days in the future

                    Get ( CurrentDate )  ≤ 14 is what I used for the expression, and it didn't work.

              • 4. Re: A script to display limited records
                philmodjunk

                     If you are using a set field step to specify find criteria in a scripted find, you'd use:

                     Set Field [ YourTable::YourdateField ; "<" & Get ( currentDate ) + 14]

                     to find all records with dates older than 14 days in the future.

                • 5. Re: A script to display limited records
                  Svetlana

                       Thank you so much for your patience with my vague explanations. You guessed correctly- I was using a set field step to specify find criteria in this scripted find. Below is the script I got using the scripted find examples you provided. Everything worked perfectly when I had the set field step as: Set Field [Logistics::Start Ship Date; Get ( CurrentDate ) + 14]; however, once I changed it to: Set Field [ YourTable::YourdateField ; "<" & Get ( currentDate ) + 14] , it no longer worked properly. I realize that there might be an error with the If/End If step, but I need some guidance on how to fix that if that is the error causing the script to not run properly.

                       Go to Layout ["Log1" (Logistics)]
                       Enter Find Mode []
                       Set Field [Logistics::Start Ship Date; "≤" & Get ( CurrentDate ) + 14]
                       Set Error Capture [On]
                       Perform Find []
                       If [not Logistics::Start Ship Date ≤ Get ( CurrentDate ) + 14 // no records were found ]
                        Show Custom Dialog ["ERROR"; "No Records were found by this search."]
                       End if
                        

                  • 6. Re: A script to display limited records
                    philmodjunk

                         How exactly does it fail to work? Do you get no records found or the incorrect records found?

                         Since specifying Get ( CurrentDate ) + 14 works for you, I suspect that it is actually working but not producing the results you wanted.

                         If  today is 3/1/2013 you had these dates in the Start Ship Date field:

                         3 / 17 / 2013
                         3 / 16 / 2013
                    3/  15 / 2013
                         3/14/2013
                         3/ 1 /2013
                         2/25/2013
                         1/1/1900

                         Any records with the dates shown in blue would be found as these are all records whith a date that is 3/15/2013 or less.

                    • 7. Re: A script to display limited records
                      Svetlana

                           I get no results found (the Show Custom Dialog step creates the dialog box with the error message).  I even entered test records with the start ship date field set to some of the dates that should work and it did not.

                           And my apologies... I made a mistake when explaining the range of dates I needed to include. It should be 14 days in the future from the current date or earlier, but not  before the current date. Does that make sense? 

                      • 8. Re: A script to display limited records
                        philmodjunk

                             Make sure that Start Ship Date is defined as a date field. This sounds like it is actually defined as a text field.

                             If you have a date field and not text, this expresion should find all records from todays date to 14 days in the future:

                             Set Field [Logistics::Start Ship Date; Get ( CurrentDate ) & "..." & Get ( CurrentDate ) + 14]

                        • 9. Re: A script to display limited records
                          Svetlana

                               Huzzah! It worked :) Thank you so much! I appreciate all of your help.