- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2023 12:43 AM - edited 03-08-2023 09:13 PM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2023 07:21 PM
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:new FiscalYearFilterOptions(4).getBeginningOfThisFiscalYear()@javascript:new FiscalYearFilterOptions(4).getEndOfThisFiscalYear()', gs.getMessage('Current Fiscal Year'));
"Current Fiscal Year" will then show up as a filter option in the interactive filters.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2023 07:21 PM
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:new FiscalYearFilterOptions(4).getBeginningOfThisFiscalYear()@javascript:new FiscalYearFilterOptions(4).getEndOfThisFiscalYear()', gs.getMessage('Current Fiscal Year'));
"Current Fiscal Year" will then show up as a filter option in the interactive filters.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2023 03:53 AM
Dear.abgovindarasu
Thank you very much!
It was very helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2024 04:43 AM
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.
Best Regards,
Pooja