Use the AutoIncrement functions built in to Epicor.
Works great and you don’t have to maintain it yourself.