13 Replies Latest reply on Mar 21, 2013 2:26 AM by ChrisVanBuren

    Weird Date Problem - Incorrect Evaluation in Script

    ChrisVanBuren

      Any ideas on this?

       

      -Customer complains about system malfunctioning.

       

      -I go to the script in question. In the script, there are nested If statements. They are like this:

       

      DayName(Get(CurrentDate)) = "Monday" etc

       

      -I run the script in the debugger. It goes to "Monday" which is odd as today is Tuesday.

       

      -I open a watch window in the data viewer, I type in DayName(Get(CurrentDate)), it says "Tuesday".

       

      -I go to the offending script step.

       

      -I open the If calc box. I make no changes.

       

      -I exit the script saving any changes

       

      -I rerun the script and it goes to Tuesday. Problem fixed.

       

       

      Hilarious.

       

       

      File recovers OK.

       

      File has just been put into use from a FM6 conversion.

       

      Thanks for any ideas.

       

      Cheers,

       

       

      Chris Van Buren

      ---------------------------------------------------------

      e: chris@zeropointdata.com

      t: +44 (0)1291 689966

      www.zeropointdata.com

       

       

      Abbey Lodge, Tintern, CHEPSTOW, NP16 6SF, UK

      ---------------------------------------------------------

        • 1. Re: Weird Date Problem - Incorrect Evaluation in Script
          BruceHerbach

          Chris,

           

          With out having your script to look at this is a bit tough to resolve.  That stated  I assume that you set this up as if Monday,elseif  Tuesday, elseif Wednesday..  rest of week.

           

          My only suggestion would be to simplify it a bit and put the day name in to a variable  Set variable[$dname; DayName(Get(CurrentDate))] and then use $dname in the if/elseif steps.   If nothing else this will have less system calls since you only use the DayName and Get(CurrentDate) functions once and can see the result in the data viewer when the script is running.

           

          HTH

          Bruce

          • 2. Re: Weird Date Problem - Incorrect Evaluation in Script
            ChrisVanBuren

            Thanks for the useful suggestion.  I haven't implemented as really my problem is solved.  I was just looking to see if anyone to could explain why FileMaker had acted "wrong".

             

            Looks like no one can... 

             

            It shall remain a mystery!

            • 3. Re: Weird Date Problem - Incorrect Evaluation in Script

              Oh Chris, do not let it remain a mystery ... this is PRIME opportunity to learn!  I cannot stand unsolved and I will help you and so will others!  There are reasons it is happening ... how could you stand it NOT to figure it out?

               

              Please PM me if you do not wish to post your empty cloned file here and we can then finalize the thread with answers.  Mysteries are simply unidentified answers. 

              • 4. Re: Weird Date Problem - Incorrect Evaluation in Script
                ChrisVanBuren

                Sadly can't post the file.  It belongs to the client and has emails directly encoded into scripts and all sorts... 

                • 5. Re: Weird Date Problem - Incorrect Evaluation in Script
                  ch0c0halic

                  Between FMP 6 and FMP7-11 and FMP12 there have been many changes to the calculation engine and to how some of the functions operate. It is not unusual for a calculation in FMP6 to get converted and have something "changed" in its dependency tree or how a specific function operates - now vs then. By opening the calculation in the Calc window you are forcing FMP to reevaluate the calculation using the current function descriptions and dependencies. When you close the calculation window FMP converts it from Text into an mathematical 'tokenized' description of the formula.

                   

                  BTW a calculation field may have a value that changes when a dependency field changes even if the dependency field value is still the same. This is because the value is 'stored' and the calculation engine has not been invoked yet to make it recalculate. For example one of the most common issues is: if I'm looking at a field (sum of a related field) and you (on your computer) change one of the related field values. Until I do something to force the evaluation (for example: Window refresh with Flush Cache) of that calculation field it doesn't change on my computer. This is one form of a dependency.

                  • 6. Re: Weird Date Problem - Incorrect Evaluation in Script
                    ChrisVanBuren

                    Here's the script.

                     

                    I have just opened an older copy of the file and can confirm the problem again.  Today is Wed and the script thinks it is Monday.

                     

                    Screen Shot 2013-03-20 at 20.01.15.png

                    • 7. Re: Weird Date Problem - Incorrect Evaluation in Script
                      BruceHerbach

                      Chris,

                       

                      Two things.  First take a copy of the file and run it through the recover process just to be sure that there is no hidden damage.  Second, I would recommend that you rework the script.  Something along the lines:

                       

                      Perform Script["Update Today Field"]

                      Set variable[$dname; Dayname(get(CurrentDate)]

                      if[$dname = "Monday"]

                             .

                             .

                      elseif[$dname = "Tuesday"]

                             .

                             .

                      elseif[....]

                      end if

                       

                      If there us no corruption,  I believe that this should clean things up and use newer script steps of set variable and elseif.  My guess is doing the rework on the script will remove the problem.

                       

                      Bruce

                      • 8. Re: Weird Date Problem - Incorrect Evaluation in Script
                        ChrisVanBuren

                        The files passes recover no problem.

                         

                        Reworking the script would make a better script but I have no need to rewrite as I have solved the problem by simplying opening the calc box on the Monday and closing it again.  Whole script works properly now. 

                         

                        My goal in posting was just to see if I could learn what happened because it was so weird.  I don't think we'll get an answer to it.  It is just a FM glitch of some kind.  Something to do with the tokenization mentioned by chocaholic perhaps.

                        • 9. Re: Weird Date Problem - Incorrect Evaluation in Script
                          debi

                          Chris,

                           

                          While nothing jumps out as really wrong with your script, I'd recommend:

                           

                          * Use FileMaker's ELSE IF in lieu of nested IFs

                           

                          * Make the comparison text Proper (not all upper case)

                           

                          * Re-write the comparison steps (don't just open and close the calc box) - create new steps from scratch and delete the old ones

                           

                          I seem to recall that pre-v7 there was an older function ( just plain Today, I think, with no parameter) that was replaced by Get (CurrentDate). FM may have updated your script to use the replacement function, but may be storing the calculation differently. (Just speculation on my part - your current calc should be updating wheneve the script is run.) If you re-write the IFs or - even better - use Bruce's suggestion to start with a variable and use THAT in the comparisons - I think you may force the calculations in much the same way it seems to update temporarily when you save your current comparisons.

                           

                          And a question: what layout do you start on? Is the script always moving to the Monday layout, or is it starting there and just not going anywhere else?

                           

                          Debi Rubel

                          FullCity Consulting

                          • 10. Re: Weird Date Problem - Incorrect Evaluation in Script
                            BruceHerbach

                            Chris,

                             

                            It sounds like your initial modification and saving of the script resolved the issue.  Sorry nothing else to offer on this.

                             

                            Bruce

                            • 11. Re: Weird Date Problem - Incorrect Evaluation in Script

                              Yes it is odd.  As Ch0c0holic says, there have been changes through versions (I have a file which works (created in 8.5) but if opened in current, its simple calculation breaks as soon as I open field definition).  A re-write is in order for sure anyway using ElseIf[].  Script obviously was using the old 'today' technique by the name of the file and since it is old, who knows but it was probably setting a date field in preferences.  Debi hit upon that reasoning.

                               

                              And, ahm, even though I dislike hardcoding, I would be sorely tempted to automate this piece a bit and just use:

                               

                              Go To Layout [ by calculation = “Main Menu “ & DayName ( Get ( CurrentDate ) )

                               

                              Also, DayOfWeek might be more efficient.  Does script throw an error?  I also wonder if the computer/server date is incorrect or if the OS date configuration was changed (to some bogus setting).  Otherwise, like Bruce, I am out of options.  At least we are giving it a good go, eh?

                               

                              • 12. Re: Weird Date Problem - Incorrect Evaluation in Script
                                ChrisVanBuren

                                >Script obviously was using the old 'today' technique

                                 

                                The FILE has used Today but the script here did not have Today in it (except in call to subscript created by conversion).  FM6 script must have been Status(CurrentDate) converted to new Get(CurrentDate).

                                 

                                Thanks to everyone for having a good go at it!

                                • 13. Re: Weird Date Problem - Incorrect Evaluation in Script
                                  ChrisVanBuren

                                  >And a question: what layout do you start on? Is the script always moving to the Monday

                                  >layout, or is it starting there and just not going anywhere else?

                                   

                                  I'm not sure about the starting layout but using the debugger you can see the execution to inside the If statement going to "Monday".