Add Year Choices to "Get Date Filter Options for Date Filters" Business Rule

Diorella Angulo
Tera Expert

Hi,

I found this article which makes sense to me to add a new choice into the Date Filter https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0749822. The thing is that I would like to include years, like 2020, 2021 and 2022 to be displayed in the filter. 

Is that possible? If so, can anyone help me how to do that?

Regards, 

6 REPLIES 6

Aman Kumar S
Kilo Patron

I think you can, as in you can create filter in list layout as after 01/01/2022 or before 31/12/2022 and use that create a new interactive filter option.

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

Best Regards
Aman Kumar

Hello Aman,

I tried the following below. I copied the query from the list layout, but I don't see it in the filter. Do you have any idea? It is the last line.

 

	answer.add('170_Last 45 minutes@javascript:gs.minutesAgoStart(45)@javascript:gs.minutesAgoEnd(0)', gs.getMessage('Last 45 minutes'));
	answer.add('175_One year ago@javascript:gs.monthsAgo(12)@javascript:gs.endOfThisMonth()', gs.getMessage('One year ago'));
	
	//DIO
	answer.add('180_2020 year@javascript:gs.dateGenerate(2020-01-01','00:00:00)@javascript:gs.dateGenerate(2020-12-31','23:59:59)', gs.getMessage('2020'));
	
}

getMessage() is something you use with UI message, that holds a string value,

Go to left navigation, type Message and add a entry for 2020, you can similarly check what values are set for Last 45 minutes, One year ago.

You can also try with:

	answer.add('180_2020 year@javascript:gs.dateGenerate(2020-01-01','00:00:00)@javascript:gs.dateGenerate(2020-12-31','23:59:59)', '2020');

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

Best Regards
Aman Kumar

Hi Aman,

I tried your code and it didn't work. It actually duplicates the current options the date filter has, and does not add the 2020.

I checked the other options like One Year but it uses beginningOfThisYear.

Can you see it? Do you have any idea?

find_real_file.png