- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2024 08:30 PM - edited 01-28-2024 08:41 PM
While creating new Request it must follow this format REQF-SN-YYYYXXXXX.
Here YYYY denotes the Current Year. For e.g. 2024. Kindly note that this should get incremented as the year changes.
XXXXX would be a five digit auto incremented value. Here, this series should start from ‘10000’ series and get incremented by count of 1.This should get reset after the end of the year.
e.g. Jan 1 2024 entitlement should be like -> REQF-SN-202410001
and Jan 1 2025 entitlement should be like -> REQF-SN-202510001
I am trying with the Before insert BR. But it is not working as expected.
I will appreciate the explanation with the Script.
Thanks In Advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2024 09:30 PM - edited 01-28-2024 09:48 PM
Hi @Munna1
You can reset the "sys_number_counter" within the same scheduled job as mentioned by @Tai Vu
Sample Script:
var gdt=new GlideDateTime();
var t=new GlideRecord('sys_number');
t.addEncodedQuery('category=your_table_name');
t.query();
if(t.next())
{
t.prefix="REQF-SN-"+gdt.getYear();
t.update();
var tt=new GlideRecord('sys_number_counter');
tt.addEncodedQuery('table=your_table_name');
tt.query();
if(tt.next())
{
tt.number=0;
tt.update();
}
}
C |
If the provided solution meets your needs, kindly consider marking it as helpful and accepting it as the solution. This helps others who may have similar questions. |
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2024 09:00 PM
Hi @Munna1
You may need a scheduled job that runs on the 1st of Jan Yearly to update the prefix in the Number Maintenance.
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2024 09:13 PM
Hi Timi,
Thanks for your response.
How can we reset these five digits auto incremented value to 10,000 again after year changes?
I will appreciate the explanation with the Script.
Thanks In Advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2024 09:30 PM - edited 01-28-2024 09:48 PM
Hi @Munna1
You can reset the "sys_number_counter" within the same scheduled job as mentioned by @Tai Vu
Sample Script:
var gdt=new GlideDateTime();
var t=new GlideRecord('sys_number');
t.addEncodedQuery('category=your_table_name');
t.query();
if(t.next())
{
t.prefix="REQF-SN-"+gdt.getYear();
t.update();
var tt=new GlideRecord('sys_number_counter');
tt.addEncodedQuery('table=your_table_name');
tt.query();
if(tt.next())
{
tt.number=0;
tt.update();
}
}
C |
If the provided solution meets your needs, kindly consider marking it as helpful and accepting it as the solution. This helps others who may have similar questions. |
Thanks and Regards,
Saurabh Gupta

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2024 09:46 PM
Hi there,
Through a Scheduled Flow which runs every Jan 1 at midnight, you could update:
sys_number record for your table and update the prefix
+
sys_number_counter record for your table and reset it to 0 or 10000
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field