This is not a sapui5 problem, it is the common behaviour of asynchronous code: you can be sure to have your data only in the success callback of the read
method.
Move the last three lines of code inside the success function and you’re done 🙂
7
solved SAPUI5: getModel returns undefined if called within the same function of setModel