Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How to create auto-generated numbers for a catalog item based on Fiscal Years

Nicholas Hromya
Giga Guru

 

Hello all,

 

I have a requirement to create auto-generated numbers for a catalog item based on Fiscal Years.

Our fiscal year starts in July.  Hence, I want these auto-generated numbers to update on July 1 of each year. 

So when the numbering starts with 25, that means it will be fiscal year 25/26 July 1, 2025 (already in past) and end June 30 2026.  Then 26 will be fiscal year 26/27 starting July 1 2026 and end June 30 2027.

I hope this makes sense.

 

The expectation is format example below:
25-50000
25-50001

26-60000
26-60001

27-70000
27-70001

 

 

It seems like I could manually create this for each fiscal year (using the Numbers), but I don't want to do this every fiscal year.  

It also seems like I could use the Fiscal Periods to set these up, but I am not sure how to use or otherwise integrate the fiscal periods to auto-generate these.

 

Seems like there is a better solution.  

Maybe some sort of onLoad script?

5 REPLIES 5

lauri457
Tera Sage

What is the actual goal you are trying to achieve with this numbering?

 

As for how to achieve this without the race conditions issues mentioned by Ken I would suggest having a look at the answer by Kieran in this community post.

Solved: Incrementing System Properties integer value by mu... - ServiceNow Community

 

But rather than using a system property I would use the number counter table [sys_number_counter], see this article:
Performance Best Practice for System Properties - ServiceNow Community

 

Then everytime you call the script include just prepend the current year and month to the number and have a scheduled script reset the number to 0 at the end of every month.

 

Or you can just use the number maintenance but give a category that is not a valid table. You just need to update the prefix with a scheduled script and delete the counter or reset it.

//create number initially
var current = new GlideRecord("sys_number");
current.newRecord()
current.setValue("category", "sc_req_item_2")
current.setValue("prefix", "26-4")
current.setValue("number", "1")
current.setValue("maximum_digits", "5")
current.setWorkflow(false)
current.insert()

//gets number and increments
GlideNumberManager.getNumber("sc_req_item_2")