On click of UI action autogenerate unique number

Sanchita02
Tera Contributor

Hello All,

 

I have a requirement that I want to autogenerate a Number for "challan" field on click of UI action. The number generated should be unique for every record 

3 REPLIES 3

Marc Mouries
ServiceNow Employee
ServiceNow Employee

Community Alums
Not applicable

Hi @Sanchita02 ,

Please create Client callable UI Actions and add below code 

 

function unique() {
	var id = "Challan" + Math.random().toString(16).slice(2);
    alert("id = " + id);
}

 

Result: 

SarthakKashya2_0-1713548854686.png

 

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak

Math.random() does not ensure the number is unique