7 Replies Latest reply on Aug 27, 2014 9:50 AM by philmodjunk

    Some how capture an object name to return after running a changelog script

    ReynaldoRamirez

      Title

      Some how capture an object name to return after running a changelog script

      Post

           Dear All,

           I have learned so much from forum over the past several years.  

           Here is my question:

           I am keeping a changelog of all the fields that are modified within my solution.  So when someone commits a change to a field, there is a trigger that runs a "Record Change Log" script. Seen below:

             
      •           Set Variable [ $Field; Value:Get ( ActiveFieldName ) ]
      •      
      •           Set Variable [ $Layout; Value:Get ( LayoutName ) ]
      •      
      •           Set Variable [ $Record; Value:Get ( RecordID ) ]
      •      
      •           // Set Variable [ $Object; Value:Get ( ActiveLayoutObjectName ) ]
      •      
      •           Go to Layout [ “Change Log” (Change Log) ]
      •      
      •           New Record/Request
      •      
      •           Set Field [ Change Log::Changed Field; $Field ]
      •      
      •           Set Field [ Change Log::Layout_Action; $Layout ]
      •      
      •           Set Field [ Change Log::Record_No; $Record ]
      •      
      •           Go to Layout [ $Layout ]
      •      
      •           // Go to Object [ Object Name: $Object ]

            

           The problem that I'm having is that when the script runs, it doesn't go back to the object where the field was...it basically resets, but with the new information.  So, now I have to click back on the object to bring it into focus. I have many tabs throughout a large database with many tables.  As you can see, I have disabled the Get (ActiveLayoutObjectName), as this didn't do what I thought it would do.  (We don't really tab through things)

            I'd rather not make a case statement using the GetLayoutObjectAttribute like:

           Case (
           GetLayoutObjectAttribute ( "Tab1" ; "isFrontTabPanel" ) ; "Tab1" ;
           GetLayoutObjectAttribute ( "Tab2" ; "isFrontTabPanel" ) ; "Tab2" ;

           etc

           )

           This would take a while to do as I have about 27 tabs over several tables to go through.  (I will if that is the only way.)  Also, I do have some tabs that are within a parent tab, will that complicate things?

            

           Looking for a better way.

           Thanks

           Rey

           Running Filemaker 13 Advanced

      screenshot.png

        • 1. Re: Some how capture an object name to return after running a changelog script
          raybaudi

          "The problem that I'm having is that when the script runs, it doesn't go back to the object where the field was..."

               I think that this problem can be solved adding this script step at the end of your COMPLETE script:

          Exit Script [ result: 0 ]

               This is because, exiting a field, automatically Filemaker goes to the next one and this action must be stopped.

          • 2. Re: Some how capture an object name to return after running a changelog script
            ReynaldoRamirez

                 This unfortunately does not solve the problem.  It still returns to the original state (as shown in the screenshot).

            • 3. Re: Some how capture an object name to return after running a changelog script
              philmodjunk

                   You can pass the object name of the current tab panel as a script parameter to your script. Then Go to Object ( Get ( ScriptParameter ) ) can return the focus to the current tab panel. This requires that you use the Name box in the inspector to give the tab panel an object name and you can use a script trigger on the tab control to update a global variable with the object name of the current tab panel so that you have that name to pass as a scrpt parameter. (Or come to think of it, your script can simply refer to the global variable in go to object...)

                   What script trigger and functions to use to identify the current tab panel depend on whether you are using an older version of FileMaker or FileMaker 12 or newer. FileMaker 11 and older users can use OnObjectModify on the tab control with GetLayoutObjectAttribute. Newer versions can use OnPanelSwitch (has different name in v12) along with get ( TriggerTargetPanel) to capture this object name in much simpler scripting than you can in older versions.

              • 4. Re: Some how capture an object name to return after running a changelog script
                ReynaldoRamirez

                     PhilModJunk! I know I am in good hands!

                     I am working on FM 13 Advanced. I tried your suggestion but for some reason I am getting "0" as the value that is passing, so here is what I have done so far.

                     1. I named all the tabs under the inspector window.

                     2. I added a OnPanelSwitch script trigger with the parameter: Get ( TriggerTargetPanel ) and added a script named "Panel Switch" with one command, which is;

                Set Variable [$$Object, Value:Get (ScriptParameter)]

                     3. I went to my OnObjectSave script that I have all my fields assigned to, which is "Records Change Log" (in my original post) and made it look as so:

                Set Variable [ $Field; Value:Get ( ActiveFieldName )
                Set Variable [ $Layout; Value:Get ( LayoutName ) ]
                Set Variable [ $Record; Value:Get ( RecordID ) ]
                Go to Layout [ “Change Log” (Change Log) ]
                New Record/Request
                Set Field [ Change Log::Changed Field; $Field ]
                Set Field [ Change Log::Layout_Action; $Layout ]
                Set Field [ Change Log::Record_No; $Record ]
                Go to Layout [ $Layout ]
                Go to Object [ Object Name: $$Object

                But the data viewer is still only showing the value as "0" and i'm getting error code 116 (which is that the object is missing)

                                    Ideas?

                      

                • 5. Re: Some how capture an object name to return after running a changelog script
                  philmodjunk

                       If you lookup Get (TriggerTargetPanel) in FileMaker help, you'll find that it returns a list of two values, one is the index number of the panel the other is the object name if you've assigned an object name via the inspector to that panel. You'll need to use GetValue ( Get ( TriggerTargetPanel ) ; 2 ) to extract the object name.

                  • 6. Re: Some how capture an object name to return after running a changelog script
                    ReynaldoRamirez

                         Awesome! That was it.  To recap.  I actually don't need a script parameter.  The OnPanelSwitch script to the "Panel Switch" script, which defines the value of the $$Object variable.

                         Thanks!!

                    • 7. Re: Some how capture an object name to return after running a changelog script
                      philmodjunk

                           Yep, that's what I had in mind.

                           The script parameter option is a good choice when you are clicking a button or tripping a script trigger on a field within a given tab panel. Then, since you already know what panel is in front (because you couldn't click the button or trip the field's trigger if it wasn't), you can pass the object name as a parameter.