I see you have ensured this happens on the server (which is good), but the solution you have outlined has a design flaw - it is possible for two or more concurrent requests for a new autoincrement value to get the same result due to race conditions.
This may help: Automatically increment order numbers