Script Include for Date Filter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2022 03:59 PM
I have added the following new filters into the "Get Date Filter Options for Date Filters" in Business Rule.
answer.add('180_2021@javascript:MyDateFilters.BeginYear(2021)@javascript:MyDateFilters.EndYear(2021)', gs.getMessage('2021'));
answer.add('185_2022@javascript:MyDateFilters.BeginYear(2022)@javascript:MyDateFilters.EndYear(2022)', gs.getMessage('2022'));
They are showing up in the Date Filter I created (see the picture).
I was suggested to create MyDateFilters Script Include but I don't have much experience with that, so I guess the code is wrong. When I pick 2021 from the filter it does not do anything, it does not filter the report. I want to show the requests closed in 2021.
Can anyone help me to figure out this?
var MyDateFilters = Class.create();
MyDateFilters.prototype = {
initialize: function() {},
myFunction: function(yr) {
function BeginYear(yr) {
return gs.dateGenerate(yr.toString() + '-01-01', '00:00:00');
}
function EndYear(yr) {
return gs.dateGenerate(yr.toString() + '-12-31', '23:59:59');
}
},
type: 'MyDateFilters'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2022 11:10 PM
Hi, this is not something I have experience with (so it may not resolve your issue), but looking at the way you are attempting to call your functions I would have expected something like
answer.add('180_2021@javascript:new MyDateFilters().BeginYear(2021)@javascript:new MyDateFilters().EndYear(2021)', gs.getMessage('2021'));
answer.add('185_2022@javascript:new MyDateFilters().BeginYear(2022)@javascript:new MyDateFilters().EndYear(2022)', gs.getMessage('2022'));
and the script include
var MyDateFilters = Class.create();
MyDateFilters.prototype = {
initialize: function() {
},
BeginYear: function(yr) {
gs.info('Testing BeginYear');
return gs.dateGenerate(yr.toString() + '-01-01', '00:00:00');
},
EndYear: function(yr) {
gs.info('Testing EndYear');
return gs.dateGenerate(yr.toString() + '-12-31', '23:59:59');
},
type: 'MyDateFilters'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2022 11:54 AM
Hi, thanks for you reply. I tried it with your modifications and it didn't work.
Actually, in the logs, I search for "Testing BeginYear" and it does not appear, so I think something is still wrong.
If you have any other idea, please let me know. I opened a case in Hi Portal, may be they can help to figure out this issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2022 09:34 AM
Hi Diorella,
Have you received a response from HI? I'm attempting to do the same. I can use GlideDateTime to specify a defined range and that works fine but when I try to call a script include to create a dynamic range it fails.
This works:
answer.add('180_Test@javascript:new GlideDateTime("2018-10-01 07:00:00")@javascript:new GlideDateTime("2019-10-01 6:59:59")', gs.getMessage('Test'));
This does not:
answer.add('041_Next 2 months@javascript:new SHCustomDateRange.getNextTwoMonthsStart()@javascript:SHCustomDateRange().getNextTwoMonthsEnd', gs.getMessage('Next 2 months'));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2022 09:12 AM
In case you did not hear back I was able to figure this out. You should have your script include return a string value for the date and insert it like this.
answer.add('220_November FY23@javascript:new GlideDateTime("'+new CustomDateRange().getMonthStart()+'")@javascript:new GlideDateTime("'+new CustomDateRange().getMonthEnd()+'")', gs.getMessage('November FY23'));
Basically you still need to use javascript:new GlideDateTime() in the business rule but you insert the script include call within the parameters. You need to be sure to keep the double quotes in there so it should look like javascript:new GlideDateTime("' + script include + '". My issue was I was replacing the double quotes as well. I was trying this and failing, javascript:new GlideDateTime(' + script include + '.
Hope this is still relevant and useful for you.