Catalog Item - Auto populate fiscal year based on date variable on form

DC9
Tera Contributor

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!

4 REPLIES 4

Dr Atul G- LNG
Tera Patron
Tera Patron

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]

****************************************************************************************************************

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.

swathisarang98
Giga Sage
Giga Sage

Hi @DC9 ,

 

You can create a string field as shown below and add Onload client script and try with the below code,

swathisarang98_0-1708623048995.png

Onload client script

swathisarang98_1-1708623078109.png

 

 

 

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

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?