6 Replies Latest reply on Mar 25, 2011 7:15 AM by DavidLott

    Global field resetting other fields???

    DavidLott

      Title

      Global field resetting other fields???

      Post

      I have a global numeric field defined for adding stock to inventory (gQuantityAdd).  After leaving that field, a script runs that adds the gQuantityAdd amount to the inventory total and then resets the gQuantityAdd to "0".  That all works fine. 

      Then I wanted to add the gQuantityAdd amount only to another separate numeric field (Quantity4Labels) in order to later run a print labels script that will print only labels for the newly added stock and not the new entire stock amount. Sounds simple enought.

      However, I have tried about 5 different ways to get the gQuantityAdd to be placed into the Quantity4Labels field without getting reset to "0" when I reset gQuantityAdd.  I've tried SetValue and then SetField, Insert Calculation , etc. and the Quantity4Labels continues to be reset to "0" when the gQuantityAdd does.

      Any help would be apprecited.

       

        • 1. Re: Global field resetting other fields???
          philmodjunk

          Is this all in one file or is the Quantity4Labels field in a different file?

          Do you have a copy of FileMaker advanced?

          Any chance that you have gQuantityAdd fields defined in two different tables?

           

          • 2. Re: Global field resetting other fields???
            DavidLott

            It is all in one file and in one table.

            Yes, I have FileMaker advanced.

            gQuantityAdd is only defined in this table.

            • 3. Re: Global field resetting other fields???
              philmodjunk

              Set Field [table::Quantity4Labels field ; table::gQuanityAdd ]

              Should do the job and won't, by itself change the value of gQuanityAdd.

              Good to see you have advanced. If you have not already done so, enable the script debugger and the data viewer, then run your script and watch the value of gQuanityAdd change as you step through the script step by step. At the very least, this should tell you exactly when the value changes to zero. If there's a script trigger firing a script that changes the value, you'll see it appear. This will likely show you why the value is changing back to zero when you didn't want it to.

              • 4. Re: Global field resetting other fields???
                DavidLott

                Thanks to the advanced features, I see what is happening... but don't know how to fix it.

                I have a script trigger set up for "on save" to run the script.  All of it is working right, but when it goes back to reset the gQuantityAdd to "0", is saves the record and then runs the script again.  For some reason it is only looping once, but that is enough to reset my Quantity4Labels as well.

                 

                Any suggestions?

                • 5. Re: Global field resetting other fields???
                  philmodjunk

                  There are two tricks to keep a script from triggering other scripts while it executes:

                  1 ) Simplest method is to create a second layout that refers to the same table occurrence as the one you are now using. Have your script select this layout to do any data changes and as it does not have any triggers defined, none will fire. This can be a blank layout. As long as it lists the same table occurrence in Show Records From on Layout Setup... it should function the same.

                  2 ) In your script use a global variable to disable all triggered scripts. In your triggered scripts, enclose the record in an If step like this:

                  If [ Not $$TriggersOff ]

                     //script steps go here

                  End IF

                  In the scripts that need triggers disabled, put these steps in place:

                  Set Variable [$$TriggersOff ; Value: True ]

                  // rest of script goes here

                  Set Variable [$$TriggersOff ; Value: False ]

                  If your script has multiple exit points due to Halt script or Exit script steps, you should precede each with that last step to disable your triggered scripts.

                  • 6. Re: Global field resetting other fields???
                    DavidLott

                    Phil,

                    Thanks!  The second layout trick did the job.  The Quantity4Labels is maintaining their values.  This has led to another problem upon printing the labels, but I put it in another post because I couldn't get the image uploaded on this one.

                    Sorry for all the trouble, but you have helped tremendously.  Thanks again!