Catalog Item - Auto populate fiscal year based on date variable on form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 06:18 AM
I have a catalog item form with a start date for the requested item; I need to auto populate another variable, fiscal year, based on the start date that is entered. I know the fiscal year calendar has start and end dates and would like to use this information to determine the correct fiscal year. How do I do this?
Your assistance will be greatly appreciated!
- Labels:
-
Request Management
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 08:55 AM
Hi @DC9
There is OOTB Auto Populate feature on variable , but i doubt it work on date.
could you please provide some screen shot for reference.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 11:16 AM
Thank you for your response, I really do not have any screen shots to share. However, imagine a form with a start date that the user enters. I want to retrieve the fiscal year for that date from the Fiscal Year calendar and load the fiscal year retrieved into a string variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 09:32 AM - edited 02-22-2024 10:34 AM
Hi @DC9 ,
You can create a string field as shown below and add Onload client script and try with the below code,
Onload client script
function onLoad() {
var year1 = new Date().getFullYear() -1 ;
var year2 = new Date().getFullYear();
var fsYear = year1 + " - " + year2 ;
// alert(year1);
// alert(year2);
// alert(fsYear);
g_form.setValue('u_fs_year',fsYear);
}
If your fiscal year is from April to march then you can try below,
Navigate to your string field Click on advanced view in that open calculated value and write the below code in script,
(function calculatedFieldValue(current) {
var gdt = new GlideDateTime(gs.nowDateTime());
var dt = new GlideDateTime(gs.nowDateTime());
if (gdt.getMonth() + 1 <= 3) {
return gdt.getYear() - 1 + " - " + dt.getYear();
} else {
var a = dt.getYear()+1;
var fs = gdt.getYear() + " - " + a;
return fs;
}
})(current);
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 11:13 AM
Thank you for the reply. I am looking for a way to get the fiscal year from the fiscal year calendar rather than calculating it based on month. In other words, I need to know how to get the fiscal year from the calendar based on a variable that user enters on form for start date. Does this make sense?