6 Replies Latest reply on Nov 22, 2013 6:48 AM by IT_User

    OnObjectSave

    IT_User

      Title

      OnObjectSave & Portal

      Post

           So it has been boggling my mind most of the day on how OnObjectSave works.  If you read below you can see how FileMaker explains it.
            
           OnObjectSave
            
           But then in the back of my mind I remember someone telling me how OnObjectSave works, but I don't think what I remember was right either.  (It had to do with two events Exit and Commit.)
            
           In any case, what is happening is that I am changing a value in a field a portal.  The script that runs deals with the field I just changed values in.  The value that is chosen is the old value and not the new value.  It messes up things because it doesn't look at the new value.  I even put the script in the OnObjectExit and OnObjectSave.
           I would rather not have to do onObjectModify (or OnObjectExit), because I really just want it to calculate when it is saved.
            
           I would like something simple to fix this.  I have done Commit, Go to Field, Go to Object, but since that requires so many variables or whatever it makes things a lot more complicated than it should be.
            
           Am I missing something?

        • 1. Re: OnObjectSave & Portal
          philmodjunk

               I'm wondering if I'm missing something:

               Using a classic layout in FileMaker 12.04 on Windows 7, I selected  a drop down list field inside a portal (it's the only field in the portal row) and used the OnObjectSave trigger to perform the following script:

               Show Custom Dialog [PortalTable::field ]

               where PortalTable::Field refers to the portal field set with the OnObjectSave trigger.

               I then tried editing the value in the field, both by selecting values from the drop down and by directly editing the field. I also tried both mouse clicks and pressing tab as a way to exit the field.

               Each time, the custom dialog popped up and showed the current value of the field. I never saw the previous value of that field.

               Can you spot anything that I'm doing differently?

          • 2. Re: OnObjectSave & Portal
            IT_User

                 I guess I should add one thing that I hope wasn't going to be a problem, but it may be the problem.

                 Instead of just two tables I am using three tables.  1 - The current layout is based on, 2 - the portal is based on, 3 - a related table to the one in the portal.  I am editing a field in table 3 from the portal.  Let me explain why.

                 I have a customers table and the portal is a statements table that is made for each month.  The third table is the payments table, because there could be multiple payments made for one statement.  Since they don't need multiple payments most of the time, I set the field up in the portal to edit the first related record of the payments table.  I have a script that will remove them from the field if it finds more than one payment made for a statement.

            • 3. Re: OnObjectSave & Portal
              philmodjunk

                   Well, I created a brand new file with three related tables:

                   Table1----<Table2----<Table3

                   Enabled "allow creation" for table 2 and 3.

                   Put a portal to Table2 on the table1 layout

                   Used the same triggered script on a field from Table3 and got the same results.

                   I then put a portal to Table3 on the layout and set up a field from Table 3 with this same trigger and script.

                   Each time I am seeing the new value of the field.

              • 4. Re: OnObjectSave & Portal
                IT_User

                     Ok, I tried it with ShowCustomDialog and it worked.  It must be my complicated Set field step.

                     Essentially it looks like this: Set Field [ Statements::Balance; Statements::DueAmount - Statements::calcSum_AmountPaid ] and that is all there is to the script.

                     So I'm using an unstored calculated sum of the payments field (AmountPaid) from the statements table.

                     (Note: I do have a calculated balance field, but for historic, reporting, and visual purposes I need a field that only updates when I want it to.)

                (P.S. Not that anyone cares, but this is my 101th comment.)

                • 5. Re: OnObjectSave & Portal
                  philmodjunk

                       That's a horse of a very different color. I would suspect that the issue there is that your aggregate function (Sum) won't update until records are committed. Exiting a field--which will trip the OnObjectSave does not commit records.

                  • 6. Re: OnObjectSave & Portal
                    IT_User

                         Ok, well, thank you for your help, Phil!