I would recommend using an OnRecordLoad script trigger if you're trying to capture the current record number into a global variable $$var. The OnRecordLoad is a post-trigger that runs after a record is made current or active.
Script triggers are all about context and order of operation. If you're getting odd or unexpected results, it's usually from using the wrong trigger for the job.
I'm using OnObjectLoad; OnRecordLoad is not available as a trigger for a popover button.
According to the fm dialog for OnObjectEnter: "the script will be run after the selected object becomes the active object". The object in this case is the popover display. The issue is that even though it has become the active object, the underlying record is not recognized as the active record before the script triggers.
you're loading the object, not the record, so you're seeing confusing results. As I said it's all about context. It's very rare to see any buggy behavior from a filemaker script trigger, and Bruce else has tested and not been able to reproduce your results. Much more common is the improper usage or understanding of trigger functions.
I'd suggest since you're trying to pull a record value, not an object value, that you use a record level script trigger, not an object based one.
Your test file has the script trigger attached to the popover itself.
My file has the script trigger attached to the popover button.
Your way is the right way.
Your file showed me where I messed up... thanks again
Thanks for that reference page.