We faced the same issue and what we did was exactly told by Dwain.
We wrote the getData() script in background processing and called background processing after passing variable. So, the delay helps in completing the variable execution and then getting the latest data.
Thanks,
Anand