Report for financial year

Nikithesh R
Tera Contributor

Hello All,

 

I have to create report incidents open in financial year. Kindly help me out how to create filter.

 

Thanks.

1 ACCEPTED SOLUTION

@Nikithesh R 

something like this, I hope this will help and you will be able to take it from here

var gr = new GlideRecord('sys_report');
gr.addQuery('sys_id','b44000f283290210a38da9e0deaad319');
gr.query();
if(gr.next())
{
	var gdt = new GlideDateTime();
	var currentYear = gdt.getYearLocalTime();
	var nextYear = currentYear + 1;

	var juneDate = currentYear + "-06-01"; // date is in YYYY-MM-dd format
	var nextYearMayDate = nextYear + "-05-31"; // date is in YYYY-MM-dd format
	
	var query = "sys_created_onBETWEENjavascript:gs.dateGenerate('" + juneDate + "','" + "00:00:00" + "')@javascript:gs.dateGenerate('" + nextYearMayDate + "','" + "00:00:00" + "')";

	gr.filter = query;
	gr.update();
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

11 REPLIES 11

Ankur Bawiskar
Tera Patron
Tera Patron

@Nikithesh R 

you will have to do some custom logic for this if you don't see any such option in the date filter

create client callable script include and query and return those INCs which are created between the financial year you want

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar 

I want create report on Incident table which are open for the financial year. Example: Current year June to Next year May.

I want this report to run every year. Can you suggest me the solution.

Thanks

@Nikithesh R 

then create a report with this year June to next year May

then run a yearly scheduled job which runs on 31st May every year and simply update the report filter condition via GlideRecord

I shared solution few years ago, simply enhance it

Can we write script to change reports filter condition? 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar 

Please help me to get Previous year June 1st in filter in below code.

var gr = new GlideRecord('sys_report');
gr.addQuery('sys_id','b44000f283290210a38da9e0deaad319');
gr.query();
if(gr.next())
{
	var gdt = new GlideDateTime(gs.nowDateTime());

	var query = "sys_created_onBETWEENjavascript:gs.dateGenerate('" + Previous year June 1st+ "','" + "00:00:00" + "')@javascript:gs.dateGenerate('" + gdt.getDate() + "','" + "00:00:00" + "')";

	gr.filter = query;
	gr.update();
}