How to execute a script when load on demand is complete

Hello, I need to load on demand data from two different db: in particular i serch for some entries in the first one's table and the put in join with the other. What is important is that after this data are loaded in memory, I need to execute a script to calculate columns. My fear is that script could be executed BEFORE all data are loaded generating errors or incomplete data. How could I control this?  Is this some Notify when complete function or so?

(1) Answer