Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Custom Field on incident table with custom number field value is like INC-23 24 -0010008

Shantanu Arora
Tera Expert

i want custom field where i want INC -23 24 -0010008 as a number

INC - Initials of incident

23 24 - current financial year

0010008- remaining number digit from the original number field of that record

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hello Shantanu,

You need to create a field on incident table for custom number field and write a business rule as per your condition either on insert or update
and write the below script 

Priyankaagarwal_0-1692944766776.png

And it will give you the solution as below

Priyankaagarwal_1-1692944807956.png

Hope this will help you in solving

Please mark the answer as helpful and correct if it helped
Thanks,
Priyanka

View solution in original post

4 REPLIES 4

Shantanu Arora
Tera Expert

Community Alums
Not applicable

Hello Shantanu,

You need to create a field on incident table for custom number field and write a business rule as per your condition either on insert or update
and write the below script 

Priyankaagarwal_0-1692944766776.png

And it will give you the solution as below

Priyankaagarwal_1-1692944807956.png

Hope this will help you in solving

Please mark the answer as helpful and correct if it helped
Thanks,
Priyanka

Thank You @Community Alums 

Nayan  Dhamane
Kilo Sage

Hello @Shantanu Arora ,

Please create a business rule and mention the below code in the it

 

var firstyear;
var secondyear;
var f;
var g;
var gdt = new GlideDateTime(gs.nowDateTime());
if(gdt.getMonth()+1 <=3)
{
firstyear = gdt.getYear()-1;
secondyear = gdt.getYear();
f = firstyear.toString().slice(2);
g =secondyear.toString().slice(2);

}
else
{
firstyear = gdt.getYear();
secondyear =  gdt.getYear()+1;
f = firstyear.toString().slice(2);
g =secondyear.toString().slice(2);
}

current.field_name='INC - '+f + ' ' + g + current.number.toString().slice(3); // as incident has 3 characters INC to be removed.

If my answer solved your issue, please mark my answer as ✅Correct & Helpful based on the Impact

Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.