Although I didn’t study your implementation in detail, the general approach seemed quite sound to me, and I would have thought it should work.
How were you setting the JobID?
If you were doing it as an onSubmit action, then I’m not surprised it didn’t work reliably.
But if you were to pass it with the form as a User Profile value, then I’d expect it to be a pretty solid solution.