I want to add one more process to the business rule 'Get Date Filter Options for Date Filters'.

M_Tomy
Tera Expert

Experts.

Tell me.


Please tell me about a business rule for an interactive filter with type Date.

 

I would like to add one more process to the business rule "getDateFilterOptions()" in the business rule "Get Date Filter Options for Date Filters".
In my country, April to March is the business delimitation of the current financial year.
(e.g. current year: 1 April 2022 - 31 March 2023)

-------------------------------------------------------------

[Example 1]

If filtered for the current year on 2023/3/31
⇒The range of target data is 2022/4/1 - 2023/3/31

 

[Example 2]

If filtered for the current year on 2023/4/1
⇒The range of the target data is 2023/4/1 - 2024/3/31.

-------------------------------------------------------------

 

I would like to add this period as one of the filters.
How should I implement this?

 

Best regards.

1 ACCEPTED SOLUTION

abgovindarasu
Tera Expert

Hi! First, add the logic you want for the time periods in a script include. For example, this would work for current fiscal year in the way you described.

 

 

var FiscalYearFilterOptions = Class.create();
FiscalYearFilterOptions.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	initialize: function(fyStartMonth) {
		this.fyStartMonth = fyStartMonth;
		this.gdt = new GlideDateTime();
		this.currentMonth = this.gdt.getMonth();
		this.currentYear = this.gdt.getYear();
	},
    getBeginningOfThisFiscalYear: function() {		
		var begin = new GlideDateTime(gs.beginningOfThisYear());
		begin.setMonthLocalTime(this.fyStartMonth);
		
		/* If still in previous fiscal year, fiscal year started last year */
		if (this.currentMonth < this.fyStartMonth) {
			begin.addYearsLocalTime(-1);
		}

		return begin.toString();
    },

    getEndOfThisFiscalYear: function() {		
		var end = new GlideDateTime(gs.beginningOfNextYear());
		end.setMonthLocalTime(this.fyStartMonth);
		
		/* If fiscal year started last year, it ends this year, not next year */
		if (this.currentMonth < this.fyStartMonth) {
			end.addYearsLocalTime(-1);
		}
                end.addSeconds(-1);
	
		return end.toString();
    },
    type: 'FiscalYearFilterOptions'
});

 

 

 

Then go to the Business Rule, Get Date Filter Options for Date Filters, and add the following at the bottom:

 

 

 

// Example, the Fiscal Year Starts in April = Month 4

answer.add('185_Current Fiscal Year@javascript&colon;new FiscalYearFilterOptions(4).getBeginningOfThisFiscalYear()@javascript&colon;new FiscalYearFilterOptions(4).getEndOfThisFiscalYear()', gs.getMessage('Current Fiscal Year'));

 

 

"Current Fiscal Year" will then show up as a filter option in the interactive filters.

View solution in original post

3 REPLIES 3

abgovindarasu
Tera Expert

Hi! First, add the logic you want for the time periods in a script include. For example, this would work for current fiscal year in the way you described.

 

 

var FiscalYearFilterOptions = Class.create();
FiscalYearFilterOptions.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	initialize: function(fyStartMonth) {
		this.fyStartMonth = fyStartMonth;
		this.gdt = new GlideDateTime();
		this.currentMonth = this.gdt.getMonth();
		this.currentYear = this.gdt.getYear();
	},
    getBeginningOfThisFiscalYear: function() {		
		var begin = new GlideDateTime(gs.beginningOfThisYear());
		begin.setMonthLocalTime(this.fyStartMonth);
		
		/* If still in previous fiscal year, fiscal year started last year */
		if (this.currentMonth < this.fyStartMonth) {
			begin.addYearsLocalTime(-1);
		}

		return begin.toString();
    },

    getEndOfThisFiscalYear: function() {		
		var end = new GlideDateTime(gs.beginningOfNextYear());
		end.setMonthLocalTime(this.fyStartMonth);
		
		/* If fiscal year started last year, it ends this year, not next year */
		if (this.currentMonth < this.fyStartMonth) {
			end.addYearsLocalTime(-1);
		}
                end.addSeconds(-1);
	
		return end.toString();
    },
    type: 'FiscalYearFilterOptions'
});

 

 

 

Then go to the Business Rule, Get Date Filter Options for Date Filters, and add the following at the bottom:

 

 

 

// Example, the Fiscal Year Starts in April = Month 4

answer.add('185_Current Fiscal Year@javascript&colon;new FiscalYearFilterOptions(4).getBeginningOfThisFiscalYear()@javascript&colon;new FiscalYearFilterOptions(4).getEndOfThisFiscalYear()', gs.getMessage('Current Fiscal Year'));

 

 

"Current Fiscal Year" will then show up as a filter option in the interactive filters.

Dear.abgovindarasu

Thank you very much!
It was very helpful.

Hi @abgovindarasu ,

I have a same requirement. Followed all the steps above but when we select current Fiscal year its not showing any record. though there are n number of record in this time frame. 

 

Request your help on this.

Pooja58_0-1718365404509.png

 

Best Regards,

Pooja