We’ve all done this, but now Steve Endow has written it down. Dynamics GP Integration Manager script to generate a fixed length number.
Dynamics GP Land: Dynamics GP Integration Manager script to generate a fixed length number
Archived post from 2015. Dynamics GP and the links it points to have changed since; check current documentation before relying on version-specific steps.