14 Replies Latest reply on Jan 14, 2014 1:00 PM by philmodjunk

    Global Field Auto Save

    KenHoopes

      Title

      Global Field Auto Save

      Post

           I am encountering an issue, where  trying to capture global field changes, I am able to surpass the capture by simply exiting the layout. Please review my issue in detail below and advise.

            

           Please note - the tables are actually more robust, I have simplified them for the purpose of understanding how to achieve my desired results.

            

           I have the following 4 tables with the following fields:

           gtbl_partdetails

           -gpart_num -> this is a global field

           -gpart_rev -> this is a global field

            

           gtbl_itemdetails

           -gitem_emp -> this is a global field

           -gitem_sn -> this is a global field

            

           tbl_parthist

           -id - >this is an autonumber

           -partnum

           -partrev

           -datemodified -> this is an auto timestamp

            

           tbl_itemhist

           -id -> this is an autonumber

           -partnum

           -partrev

           -sn

           -emp

           -datecreated -> this is an auto timestamp

            

           I then have two layouts, one for updateing the part info, which changes only monthly, and one for updating the item info which changes with each item made.

           On my part information submission layout i have two data fields for gtbl_partdetails::gpart_num and gtbl_partdetails::gpart_rev. I then have two available buttons, one is submit, which launches a script that uses open layout--> new record --> set fields --> commit --> return to layout. This works great. i then get a history of each time the global fields have been changed.

           However, if the user makes changes to the fields, and uses the close button, which simply returns them to a previous layout, the global fields are still updated, but the change is not tracked in the history table.

           It's as if each time i tab out of the global field, the data in the global field is saved. I do not want them to be able to edit the global fields unless they use the submit button to record the change in history.

           I hope it makes sense... maybe?

        • 1. Re: Global Field Auto Save
          philmodjunk

               But what result do you want to take place if they click close? Do you want to also save the data when they click close? Or do you want this to be a "cancel" action where the global fields are simply cleared and the data is not saved?

               Both options are possible. It's just a matter of what script you set up to be performed when the close button is clicked.

          • 2. Re: Global Field Auto Save
            KenHoopes

                 I want changes to be discarded.

                 I need the global fields to remain populated because i use them on the second layout (non-editable) as a part of a script to record build history with serial numbers. So if they make changes to the global fields on the part information submission layout, and do not press submit to run the script that saves the changes to a history table, then i want the changes discarded.

            • 3. Re: Global Field Auto Save
              philmodjunk

                   Then you simply need a script that restores the values in the global fields to their initial "default" values. A button can run a script that uses set field steps to reset the global fields before either closing the window or changing layouts to return the user to where they started.

              • 4. Re: Global Field Auto Save
                KenHoopes

                     Ok, so I think 1 option is to...

                      

                     add IF statements at the beginning of the script for the close button that compare what is currently in the global field to the latest entry in the history field, and set the global field to match where they don't match.

                     It seems like it will work, but seems a bit overkill, although maybe I am not completely understanding the global fields.

                     My only concern with this is ensuring that I am comparing it to the latest record. All entries in the history table do have a date/time timestamp, and I know I could do it in SQL, but not sure how to do it yet in FM

                • 5. Re: Global Field Auto Save
                  philmodjunk

                       Think of a global field as that "Unassigned text box" you might put on a VB or MS Access form, but which is accessible from any script, calculation and layout in your database file.

                       I'd need to understand a big more about your database design in order to understand the precise details of how you would "compare it to the latest records".

                       Personally, I'd set up the script that takes the user to this layout to also set the global fields to any needed values so that the user sees the desired data in them each time they open the window to it or navigate to that layout. I wouldn't have the close button do anything to change the global fields, just take the user back to where they need to be.

                  • 6. Re: Global Field Auto Save
                    philmodjunk

                         I don't see why you care whether or not they change the data in a global field.

                         Let's back up to what appears to be a missing detail in your work flow:

                         

                    "tbl_globalcableitem..." layout is opened,data is entered into the 3 global fields, then the submit button is pressed

                         What happens in between the blue and red portions of that description?

                         From your other posts, I would expect to see some indication that data is loaded into the global fields because you otherwise would not need to do anything but  clear the fields when the user clicks the close button.

                    • 7. Re: Global Field Auto Save
                      philmodjunk
                           

                                Basically, these global submission layouts are being used to provide the people on the floor a way of storing very regularly used data, so they dont have to re-key it every time. The global fields are used every time a new test record is saved.

                           Then I would use some set field steps to set those global fields to the correct values at the point between the "red" and "blue" of my last post. In other words, when a user clicks a button to get to this layout, the script sets the global fields as part of bringing up the needed layout. What data is in the fields when the user clicks closed can then be ignored--it will be changed anyway the next time the user initiates this process.

                      • 8. Re: Global Field Auto Save
                        KenHoopes

                             Hmmm, weare still not synching up on the objective, so let me rephrase this.

                             What I want on one form is 3 global fields that are never updated unless the submit button is pressed. If the close button is used i want any changes made to be discarded.

                             So initial open --> user enters data, and presses submit. Global data is allowed to remain in the global field.

                             Second open --> user enters data, and presses close. Global data is reset to what it was when layout was opened.

                             Third open --> user enters data, and presses submit. Global data changes are allowed to remain in the global field.

                              

                             On a side note, thanks for all of your help Phil. I cant tell you how helpful you have been with my transition into FM.

                        • 9. Re: Global Field Auto Save
                          philmodjunk
                               

                                    What I want on one form is 3 global fields that are never updated unless the submit button is pressed. If the close button is used i want any changes made to be discarded.

                               Which is exactly what will happen if you follow my suggestion.

                               

                                    Global data is reset to what it was when layout was opened.

                               With what I am suggesting, that happens each time the user clicks the button to go to this layout. The fact that altered data is left in the global fields won't matter because it will be changed back the next time the user returns to the layout anyway.

                          • 10. Re: Global Field Auto Save
                            philmodjunk

                                 Here's a simple demo file of what I am describing: https://dl.dropboxusercontent.com/u/78737945/GlobalFieldSubmitDataDemo.fmp12

                            • 11. Re: Global Field Auto Save
                              KenHoopes

                                   The data on the global fields is not only being used on this layout. This data is referenced in other layouts. So if the user changes it, but doesnt click submit, there will be no history of who changed it, however, as this field is reflected on other layouts, they could potentially get bad data.

                                    

                                   I just sent you a link to the DB in your messages.

                                    

                              • 12. Re: Global Field Auto Save
                                philmodjunk

                                     That explains the difference then. But is easily fixed with set field steps that execute to restore the values when the close button is clicked. Note that you don't actually have to check to see if the value is changed.

                                     If [ Table::Field = "Apple" ]
                                        Set FIeld [Table::Field ; "Apple" ]
                                     End IF

                                     and

                                     Set FIeld [Table::Field ; "Apple" ]

                                     Produce identical results.

                                • 13. Re: Global Field Auto Save
                                  KenHoopes

                                       Ok, I am absolutely with you now, on what you are proposing. Is there a way to:

                                        

                                  Set FIeld [Table1::Fielda ; Table2::Fielda ]

                                  where

                                  [Table2::datemodified] = MAX[Table2::datemodified]

                                  • 14. Re: Global Field Auto Save
                                    philmodjunk

                                         Open Manage | Database | Relationships

                                         Find the relationship line defining the relationship between Table1 and Table2. Double Click the line to open Relationship Details.

                                         On the Table2 side of the relationship, click sort and specify that the related records be sorted in descending order by DateModified.

                                         Now

                                    Set FIeld [Table1::Fielda ; Table2::Fielda ]

                                    will put the data from Fielda from the related table2 record with the most recent dateModified date into Table1::fielda. But note that with the relationship, you may not need to even do that. In some cases, you may just choose to put Table2::fielda on your Table1 layout and it will always show data from the most recently modified related record from Table2.