Seems like we are missing some information. I don't see this custom dialog box in your script so I can only assume it is part of a script that is being called by a script trigger. Did you try running this script with the Script Debugger to see if the script triggers another script?
If this is the case then you may need to suppress the script trigger(s). Search the forum for many examples of this, but here's a great idea from the great PhilModJunk
Thanks for your help.
Here is first script that triggers the dialog box you mentioned:
Set Error Capture [ On ]
Go to Layout [ “Invoice Creation Dialog” (Invoices_) ]
Go to Field [ Invoices_::Customer Company Name ]
Here is quick video of the scripts in action to see: