Auto Numbers with a date prefix

Job2
Giga Contributor

Hi,

 

We want to to auto-numbering on a certain table with a date prefix but I am a bit stuck...  

I can't find anyone who has posted this in the past on this community but I do know the solution exists...  

Any idea anyone?  

1 ACCEPTED SOLUTION

Job2
Giga Contributor

We used condition: When = OnDisplay


with the following script to add the date of today as a prefix:



var month = '', day='', year='';




var gdt =new GlideDateTime();


month = gdt.getMonth();


day=gdt.getDayOfMonth();


year=gdt.getYear();




var array='';


array=current.number.split('VLN');


current.number='VLN'+day+month+year+array[1];


//current.number = current.number + month;


View solution in original post

7 REPLIES 7

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

Nothing out of the box will do this, but you can create a business rule that runs on insert to set the number to whatever type of sequence you want.   The only out of the box method is using "Number Maintenance" which allows you to assign a prefix and then a number will increment.


Job2
Giga Contributor

We used condition: When = OnDisplay


with the following script to add the date of today as a prefix:



var month = '', day='', year='';




var gdt =new GlideDateTime();


month = gdt.getMonth();


day=gdt.getDayOfMonth();


year=gdt.getYear();




var array='';


array=current.number.split('VLN');


current.number='VLN'+day+month+year+array[1];


//current.number = current.number + month;


There is one problem in this . 

After submission  of the form when i viewed the form then it's displaying VLN2020092020090001.

it's repeating the year and date .How to solve this can any help !!