(cc to the list)
For a more helpful response, we would certainly need to look at your code and run it by ourselves.
I recommend you to run your function…
$SWM:dialog.new
…outside your web application, e.g. in the BqseX GUI. This may help you to isolate the problematic part of the code.