Darn, my crystal ball still isn't working.
I can guess that your script changes layouts to create a record in the audit log table.
If so, I can think of two options:
Use the MagicKey method to create the audit log record. This method creates new records in another table without changing layouts or opening new windows.
Save all your audit log data in lists or arrays using global variables. Don't create audit log records from those variables until the popover closes.