Hello Dinesh,
I reproduced your use case in Mendix 9.17. To be able to get the correct ID you have to turn on the “refresh on context” settings otherwise you will log the ID before the object is initialized,
Hope this helps also for you in Mendix 8.
See screenshot: