"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.
This unfortunately does not solve the problem. It still returns to the original state (as shown in the screenshot).
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.
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) ]
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)
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.
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.
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.