11 Replies Latest reply on Feb 23, 2010 4:35 PM by comment_1

    Operators for "Current Year" and "Previous Year"?

    LeoB

      Title

      Operators for "Current Year" and "Previous Year"?

      Post

      I'm trying to write a find script that would display All Records, Records Current Year, and Records Previous Year by a button.

       

      I can do that by inserting the actual year, but then the script would have to be modified on 1/1/2011 and every year thereafter.

       

      I've been looking but can't find any operator for CurrentYear or PreviousYear (or CurrentYear - 1).

       

      Any way to do this?

       

      Thanks

        • 1. Re: Operators for "Current Year" and "Previous Year"?
          mrvodka
            

          The script parameter on the button for the current year would be: "*/*/" & Year ( Get ( CurrentDate ) )

          Previous year: "*/*/" & Year ( Get ( CurrentDate ) ) - 1

           

           

          The script would then just take that script parameter and pass it along.

           

          Enter Find Mode []

          Set Field [ YourDateField; Get ( ScriptParameter ) ]

          Perform Find []

           

           

          Dont forget to error trap for invalid dates, no records found, etc.

           

           

          Also I just wanted to mention as a side note, you could just put in the year such as 2010 and it will find all the records in 2010 but IIRC this shortcut may not always work when dealing with other international date formats.

           

          • 2. Re: Operators for "Current Year" and "Previous Year"?
            LeoB
              

            mr-v:

             

            This makes sense, and uses something I've not tried before (script parameters).

             

            However,  when I try to insert the script parameter, it keeps returning an error screen that highlights "*/*/" and states that it is not a valid date parameter.

             

            I tried it without and with the parentheses in various locations, including after Year, but keep getting the same error message.

             

            Any ideas?

             

            Thanks for the help/

            • 3. Re: Operators for "Current Year" and "Previous Year"?
              mrvodka
                

              You are putting the script parameter when you specify the script for your button correct?

               

               

              • 4. Re: Operators for "Current Year" and "Previous Year"?
                LeoB
                  

                Correct.  I was trying to write the script and would then link it to a button on a List Layout of all Activities.

                 

                I posted an image of the script screen here:

                 

                http://img697.imageshack.us/img697/3972/scriptparameter.jpg

                 

                Thanks

                 

                 

                • 5. Re: Operators for "Current Year" and "Previous Year"?
                  mrvodka
                     Why is there a Get ( in the beginning?
                  • 6. Re: Operators for "Current Year" and "Previous Year"?
                    LeoB
                      

                    Mr. V:

                     

                    If you have time, I'm stumped.  I got sidetracked on another issue for a few days after I was stuck on trying to make this work.  I went back at it, and I think I'm not understanding exactly how to create a script parameter.

                     

                    I just read the help page (which was no help at all) and searched the forum, and it looks like a script parameter is something that is written and can then be called into any script via Get ( ScriptParameter ).  However, I cannot figure out how to actually write the script parameter.  Where would they be?

                     

                    You mentioned defining it off the button, but I can't figure out how.

                     

                    If you can point me in a direction to look this up, I'd appreciate it.

                     

                    Thanks

                    • 7. Re: Operators for "Current Year" and "Previous Year"?
                      philmodjunk
                         When you set up a button to perform a script, you select the perform script options and click Specify to select the script to be run. This pops up a dialog box with an "optional script parameter" box at the bottom. You can enter a parameter in this box or click the edit button to design a calculation that will evaluate and pass its result as the parameter to your script.
                      • 8. Re: Operators for "Current Year" and "Previous Year"?
                        LeoB
                          

                        That sound you heard a while ago -- thwap -- was what Click & Clack on Car Talk call a dope slap.

                         

                        OK -- I found it (hiding in plain view), but when inserting the parameter mr_v recommended, it won't highlight the OK button to save.

                         

                        I am putting in exactly:  "*/*/"_&_Year_(_Get_(_CurrrentDate_)_)  (The underscores are spaces.)

                         

                        Any idea of what I'm doing wrong.

                         

                        Thanks

                        • 9. Re: Operators for "Current Year" and "Previous Year"?
                          philmodjunk
                            

                          I had to play around with the dialog to replicate that.

                           

                          Make sure you've clicked the name of a script so that filemaker knows which script to perform (and pass the parameter to). :smileywink:

                           

                          It doesn't appear to be the issue in this case, but for expressions like this, it's a good idea to click the edit button so that you can use the script editor to build them. You get a bit more feedback on any typos that way.

                          • 10. Re: Operators for "Current Year" and "Previous Year"?
                            mrvodka
                               Phil already pointed out what most likely the issue would be being that a script probably was not selected. However, I just wanted to add that the spaces dont matter for the calc. Its just a formatting preferance for easier readability.
                            • 11. Re: Operators for "Current Year" and "Previous Year"?
                              comment_1
                                

                              mr_vodka wrote:

                              you could just put in the year such as 2010 and it will find all the records in 2010 but IIRC this shortcut may not always work when dealing with other international date formats.


                              I believe it's the other way round: a 4-digit year by itself will work with any date format, but */*/2010 will only work with m/d/y and d/m/y formats, not y/m/d.

                               

                               

                              I would make the script parameter either -1 or empty, and the script:

                               

                              Enter Find Mode []

                              Set Field [ YourDateField ; Year ( Get (CurrentDate) ) + Get (ScriptParameter) ]

                              Perform Find []