14 Replies Latest reply on Mar 5, 2014 8:37 AM by Matty_1






           Hi Guys,

           I'm completely confused and before I get into details and provide scripts I will give a general overview in hopes that it's a simple fix.  If more info is needed I suppose we can cross that bridge then.

           So my issue is this: I have three fields, Quantity, Percentage and InventoryBalance.  The user enters a percentage into the percentage field.  Based on the percentage chosen, the quantity field auto-enters a calculated quantity.  Finally, based on the results of the quantity, Inventory balance auto enters another calculation removing the quantity from the current inventory.  I do this so that we can go look at what inventory was at the time of a particular transaction.  Clear as mud?!

           What is strange is this, if I leave out a particular set of script triggers in the OnObjectEnter and OnObjectSave the InventoryBalance field seems to update only occasionally and incorrectly.  When both triggers are in it works 100%, no matter what.  The triggers I use are universal triggers I put in every single field in my entire database.   It verifies if changes have been made when records are closed and if so it asks for an explanation.

           The strangeness continues ... the issue with this one particular layout is the danger of accidentally going into negative inventory so I sought to create a script which would verify and help the user calculate percentages if need be.  I put this trigger in OnObjectValidate.  I now seem to have the same issue, my InventoryBalance field doesn't update properly and I do't have a hot clue why it would do that.

           Any ideas?!

        • 1. Re: OnObjectValidate

               Sounds like your OnObjectSave trigger might be doing a Commit Records--either as an explicit script step or as a side effect of another script step in the script. OnObjectValidate kicks in before OnObjectSave and thus the commit records action has not yet taken place.

          • 2. Re: OnObjectValidate

                 You are correct, there is a commit record step in the OnObjectSave but when I have the script in OnObjectValidate its as though the commit doesn't work and as I mentioned earlier, the InventoryBalance doesn't calculate.

            • 3. Re: OnObjectValidate

                   Here's the script I'm trying to run that seems to break it.

              • 4. Re: OnObjectValidate

                     As you can see, what I'm trying to do is all the math before the record commits so that I can make the changes required before the commit as well.  Then in theory everything should line up after that.

                • 5. Re: OnObjectValidate

                       It would be helpful to see the actual calculation that is failing to update as you expected it to update.

                       Your script does not commit records unless the calc evaluates as negative and the user does not click button 1 in the dialog and then only at the end. That illustrates my point that your OnObjectValidate script is running before the record is committed unlike OnObjectSave--which is processed after this trigger controlled script has executed.

                       And since you have everything run via script triggers, it may be simpler to not try the auto-entered calculation at all and use the script to update the field(s) value(s) instead.

                  • 6. Re: OnObjectValidate

                         yeah maybe I should.  I've just had better luck with auto calculates in the passed and I don't know what I did to break this one.  I could have sworn I had everything functioning as expected this mooring and now nothing seems to function as expected.

                    • 7. Re: OnObjectValidate

                           Does anything change if you put in a commit records as the third line of your script? (just after the 2nd set variable step)

                      • 8. Re: OnObjectValidate

                             OK, *shakes head in disappointment* I figured out what I did different that broke the last script.

                             The issue was that I was using the field that auto-entered the inventory ( zanInventoryCALC ) , in the variable calculation .  Thought it would look cleaner if I did so but then it broke the ability for the field to run it's own calculation ....  Banging my head against the wall I copy pasted the calculation from the auto-enter field ( zanInventoryCALC ) back into the variable calculations and everything started working as expected again.  I must have been focusing on something else when I made the change and didn't notice that it initially broke the auto-enter.

                        • 9. Re: OnObjectValidate

                               I had wondered about that, but you were so confident that it worked for you. Auto-enter calculations that refer to data from other records/tables will not automatically update when data in those other records is modified. They only update if fields in the same record referenced by the calculation are modified and then only if the "do not replace existing values" check box is cleared.

                               You may find this thread on using an "inventory ledger" to track inventory to be of interest: Managing Inventory using a Transactions Ledger

                          • 10. Re: OnObjectValidate

                                 That wasn't the issue, I think it had something to do with the fact that the I was expecting updated from was the same field that was part of calculations in the script which must have locked it right when it should have been refreshing.  Does that make sense to you?  All I did was copy paste the calculation from auto-enter SalesMix_Sales::zanInventoryCALC field and replaces all the SalesMis_Sales::zanInventoryCALC in the script with the calculation (which is in theory one and the same) and it started working as anticipated.


                                 Makes sense?

                            • 11. Re: OnObjectValidate

                                   That doesn't make sense. A script can't "lock" an auto-entered calc from updating, But I have several times tried to point out that your script may be accessing the field before it has actually updated and suggested that a commit records script step executed before you try to access the field might make a difference.

                              • 12. Re: OnObjectValidate

                                     oh I see, I'm sorry.  Clearly misunderstood you there. ok well the field being part of the script is certainly what caused the issue.

                                • 13. Re: OnObjectValidate

                                       I will politely disagree.

                                  • 14. Re: OnObjectValidate

                                         man I keep screwing this up aren't I?  Again poor wording.  You're right, the field being part of the script wasn't the issue.  What I was trying to say is that rather then trying to figure out where I should put a commit or figure out why the results weren't correct I simply copy pasted the formula from the auto-enter field into the script replacing the field itself and by doing so it produced the results I was looking for.


                                         Still wrong?! lol