Autoincrement string field for employee ID

Daniel Shock
Kilo Sage

We have a field on the user table u_employee_id.  It is a string field that contains only numbers.  It has to have 6 digits even if it is only number 50 - so 000050 for example.   The numbering was assigned in a random-ish way by human resources originally, so there are gaps... we might start at 000001 and go to 000059...and then skip to 000124. 

I would like a business rule (I assume) that will auto increment and assign the next available number when a user is inserted.  Filling in the gaps where they exist.  Can anyone assist in the construction of this script?  This seems to be a starting point:

Autoincrement stringfield (custom)

Thanks so much for any assistance you can provide!

 

3 REPLIES 3

Mike Allen
Mega Sage

The easiest way to do this is through Number Maintenance.  Just add the table and number to the number Maintenance table, then add javascript:getNextObjNumberPadded(); to the default value of the field.  This will not fill in the blanks, but will increment from the largest number.

I agree with Mike. Only thing that I would add is that in the table configuration, check the 'atuonumber' flag:

find_real_file.png

Bear in mind that this step in irreversible. Atleast I havent found a way to reverse it.

a fair suggestion.  But, I only want this to happen when there is not already an employee ID assigned... we have other users that are not employees that do not get an employee ID.