Hi,
use FINAL window instead of secondary window as final window will process after the processing of all the other windows.
and if you are using table then make use of footer and events of the smart form or Create a template or final window after the main window and select check box "AT THE END OF MAIN WINDOW".
thanks!!