13 Replies Latest reply on Dec 12, 2016 7:07 AM by StevenM

    Could Someone explain this behaviour!?

    StevenM

      Could someone please shed some light on this behaviour!?

      Why does the Auto Enter Calc evaluate to something different in the Data Viewer?

      Its nothing to do with script triggers changing the value and I can't for the life of me crack this!

      For some reason, the first 2 Case Statements never evaluate correctly. They evaluate as "", checked this using a LET statement to set $$ vars. And it executes on the 3rd as it evaluates to True.

      I've broke this down and added the Individual Statement Lines one at a time.

      It evaluated correctly when only Statement 1 was used.
      It evaluated correctly when Statement 1 & 2 where used.
      When Statement 1, 2 and 3 existed, it didn't evaluate the first 2 statements and executed the 3rd!

      Please if anybody can shed any light on this it'd be much appreciated! I'm swaying to something in the Dependency Tree is the issue but I don't understand fully how FileMaker determines this tree.

      I've also recovered the file but to no avail.

        • 1. Re: Could Someone explain this behaviour!?
          wimdecorte

          You don't show what is in the 'is tax exempt' field for that record.  Remember that Case() will stop at the first true statement and not evaluate the rest of the statements.  So for that record you have in the screenshot the 'is tax exempt' field is almost certainly set to 'yes'

           

          Another possibility is that in the field definition, the context for the calc is different than what you'd expect.  That can lead to a difference calc result in the field than what you can see in the data viewer.  The data viewer will use your current context, whereas a calc will use the context as it is set in the calc definition.  Look for the 'evaluate this calculation from the context of' at the top of the calc dialog.  It is easy to overlook.

          • 2. Re: Could Someone explain this behaviour!?
            StevenM

            Thanks wimdecorte.

            The Quote_Line_Items::is_tax_exempt value is "Yes". This field is an auto enter that pulls in this Yes value from its parent Quote table.

             

            So you are right, it is set to Yes. But the Quote_Line_Items::Tax_Code value is using the exact same Expression in the data viewer but evaluates differently upon record creation. And this is where I can't understand what's going on.

             

            wimdecorte wrote:

             

            Another possibility is that in the field definition, the context for the calc is different than what you'd expect. That can lead to a difference calc result in the field than what you can see in the data viewer. The data viewer will use your current context, whereas a calc will use the context as it is set in the calc definition. Look for the 'evaluate this calculation from the context of' at the top of the calc dialog. It is easy to overlook.

             

            I assumed this too, but its evaluating from the same TO associated with the layout that the data viewer is currently evaluating on.

            • 3. Re: Could Someone explain this behaviour!?
              David Moyer

              Hi,

              you might double-check that the records are committed.  You might also try "Refresh Values" in the Data Viewer, just to rule that out.

              • 4. Re: Could Someone explain this behaviour!?
                StevenM

                Thanks David. It's committing correctly and the refresh values doesn't do anything.

                • 5. Re: Could Someone explain this behaviour!?
                  David Moyer

                  you might also try adding the individual fields to the Data Viewer, like Quote_Line_Items::is_tax_exempt,  Stock_For_Quote_Line_Items::Tax_Code, etc.

                  • 6. Re: Could Someone explain this behaviour!?
                    StevenM

                    I have mate. What really throws me is this. This is being used on the Quote_Line_Item::Tax_Code field.

                     

                    Case (
                    
                        // Statement 1
                        Quote_Line_Items::is_tax_exempt = "Yes" ;
                            "Hello" ;
                    
                        // Default
                        "Non"
                    )
                    

                     

                    Will execute to "Hello"

                     

                    This

                     

                    Case (
                    
                        // Statement 1
                        Quote_Line_Items::is_tax_exempt = "Yes" ; 
                            "Hello" ;
                    
                        // Statement 2
                        not IsEmpty (Clients_Detail_Quote_Line_Items::Default_Tax_Code) ; 
                            Clients_Detail_Quote_Line_Items::Default_Tax_Code ; 
                    
                        // Default
                        "Non"
                    )
                    

                     

                    Will execute to "Hello"

                     

                    But this...

                     

                    Case (
                    
                        // Statement 1
                        Quote_Line_Items::is_tax_exempt = "Yes" ; 
                            "Hello" ;
                    
                    
                        // Statement 2
                        not IsEmpty (Clients_Detail_Quote_Line_Items::Default_Tax_Code) ; 
                            Clients_Detail_Quote_Line_Items::Default_Tax_Code ; 
                    
                    
                        // Statement 3
                        not IsEmpty (Stock_For_Quote_Line_Items::Tax_Code) ; 
                            Stock_For_Quote_Line_Items::Tax_Code;
                    
                        // Default
                        "Non"
                    )
                    

                     

                    Will execute to "TU". TU is the value in Stock_For_Quote_Line_Items::Tax_Code. Why it skips over the first 2 statements when this 3rd one is introduced is causing me to destroy my desk with my head...so to speak.

                    • 7. Re: Could Someone explain this behaviour!?
                      David Moyer

                      that sounds like corruption - I see nothing wrong with it.  As long as the context is the same as the first two iterations (i.e.is_tax_exempt = Yes), it should result with "Hello".

                      (I am confused by the line numbers - I assume you are within the definition of a Set Variable or Set Field script step.  Are the line number new to FM15?)

                      • 8. Re: Could Someone explain this behaviour!?
                        StevenM
                        You can quote with Syntax highlighting with this editor.
                        See! :)
                        
                        Hello World
                        

                         

                        The code line numbering is just a feature on this site when quoting code.

                         

                        See I thought corruption too but I rebuilt the file with no issues this morning :/

                         

                        It's got to be context, it always ends up something like that but I can't see it right now.

                        • 9. Re: Could Someone explain this behaviour!?
                          BruceRobertson

                          That is a VERY strange case statement, which to me, reads a lot like this:

                           

                          Case(

                          Eyecolor="blue"; "this";

                          HeightOfSomeOtherAttribute = "6" ; "orange";

                          DefaultsFavoriteSaladDressing = "Blue cheese"; 145

                          )

                           

                          Also, I suggest you not bother with the data viewer but as a temporary measure, place all the fields mentioned in the calculation directly on the layout.

                           

                          case statement.png

                          • 10. Re: Could Someone explain this behaviour!?
                            taylorsharpe

                            Assuming the same context, obviously that should not happen.  I've seen a calc go bad for some reason before.  Before this calc, have a separate calc that does just this and create it afresh, don't duplicate this line.  See if that makes a difference.  If not, make a series of nested IF's to see if that makes a difference.  I'm betting there is some corruption under the hood in the line you are working on and rewriting that calc may clear it up.  But that is just a wild stab in the dark for something to try. 

                            • 11. Re: Could Someone explain this behaviour!?
                              FileKraft

                              another context to consider is privilege sets - the data viewer evaluates full access if idle - but when running during a script execution under a limited privilege set different from full access the results might be different.

                               

                              to evade this run your script if security allows full access and compare again.

                              • 12. Re: Could Someone explain this behaviour!?
                                StevenM

                                I've got a working solution for it. I've unchecked the Do Not Replace check box. I'm always wary of doing this on a field that a user can can manually change and the trigger happening but in this instance I should be fine.

                                 

                                Thanks everyone for your ideas!

                                1 of 1 people found this helpful
                                • 13. Re: Could Someone explain this behaviour!?
                                  StevenM

                                  It does make sense lol

                                   

                                  The idea is this.

                                   

                                  If the Quote has been marked as Tax Exempt, then place "Non" (Here I had Hello for testing)

                                  If the Related Customer uses a Tax Code, to use this.

                                  If the Related Stock Item has a Tax Code, to use this.

                                  If the Settings has a default Tax Code, to use this.

                                  Otherwise place Non in the field.

                                   

                                  Thanks for your suggestion though. I hadn't thought about placing the fields actually on the layout.