I have this code which is working fine for generating auto increase “order field”.
Now the question is how can I don’t make it increase the number next time, in case user dont save the record.
I am using uniqueNumbersService for auto increment but the limitation of it is , it wont setCurrentNumber.
For that I need to use uniqueNumbersAPI which is accessible only from the core module.
May be I can create a custom service and use it in controller but is it recommended?
Please help.
You do not want to create the unique numbers in the client tier. This is an example of how I handle unique numbers. In my case, I always set the number property to TBD (To Be Determined) and set the number when all client side validations have been performed and the record is being inserted.
In this example, I inherit from a Company and create a unique number in the format for example CU1803001 where the number represents a customer created in the third month of 2018 and is first. The number resets to 1 every month.
Are you using an IDE? If so, set a breakpoint and see if you are even getting into the class on the insert. Also, make sure that you have restarted your app, as I have had issues where event listeners don’t register correctly on creation.
Well I dont know where you are suggesting to add @Listener annotation, but this is working great as expected after the app restart
Thank you so much guys @vsposato5370@IanE . You saved my day.
Great news! For later reference, the @Listeners goes at the top of the entity that is being listened to. But if it is working, then it is probably there.