Script for Unique number generation with 6 digit limit

Devi16
Tera Contributor

Hi Forum,

Thanks in advance for helping me.

I have some requirement, we have some custom table with one custom number field, so would like to generate a unique number for this field based on the other reference field value, on the reference field we have some value, so whenever record insert into the main table we would like to get the reference field value (500) + newly generated unique value. How can I achieve this using BR.

EX:  500123456.

10 REPLIES 10

Kieran Anson
Kilo Patron

Hi Rdevi,

Go to Number Maintenance and create a new number record like the following, setting the table to the table you want.

find_real_file.png

In your Business Rule, use the following to get the next unique number

var nm = new NumberManager(current.sys_meta.name);
answer = nm.getNextObjNumber();

Thanks for the replay, but I can't go with number maintenance.

 

Tony Chatfield1
Kilo Patron

Hi, I would suggest you use number maintainence to increment a number in 1 field, and in another field concatenate the reference field and the number on insert. But this new concatenated number will not show until after the record is saved, and you may be able to use a client script to to set the value before insert on the form.

Hemant Goldar
Mega Sage
Mega Sage

Hi,

Below Business Rule code will help you to create a unique random number.

var max=600000
var min=500000//create a random unique number from 500000

current.u_auto_number=Math.floor(Math.random() * (max- min)) + min;

OR

You can also set a unique random number by the default value of the field to

javascript:current.u_auto_number=Math.floor(Math.random() * (600000 - 50000)) + 50000;

 

Hope this helps!

Please mark the reply as Helpful/Correct, if applicable.

Regards,
Hemant