How to add “Next Wednesday” as a dynamic date option in filter condition (Created field)?

SangareswarK
Tera Contributor

Hi everyone,

I am trying to add a custom dynamic date option called “Next Wednesday” in the condition builder for date fields like Created, similar to the existing options such as Today, Yesterday, Tomorrow, This week, Next week, This month, etc.

 

My requirement:

                 When selecting Created → on or before → Next Wednesday,
                 ServiceNow should automatically convert the value to the correct date.

 

Example:

             1. If today is 11-Dec-2025, “Next Wednesday” should automatically resolve to 17-Dec-2025.

             2.If I run the same filter on 4-Jan-2026, it should automatically resolve to 7-Jan-2026.

5 REPLIES 5

Karunakaran
Giga Guru

Hi @SangareswarK ,

 

Have you tried "Create scripted filters" ?
https://www.servicenow.com/docs/bundle/yokohama-platform-user-interface/page/use/using-lists/task/t_...



In this you need to create a script include.
In the script include function, you can try GlideDateTime with getDayofWeek() for wednesday. Or based on your requirement you can change this logic.

Hope this helps.
Thanks.

maheshkhatal
Mega Sage
Mega Sage

@SangareswarK You need to use GlideDateTime API. Create a date object on the date that you are passing, get the day of the week(0-6) and then do gdt.addDays(whatver_day_wendnesday) and then you can do gdt.getDate(). This will give you next wednesday.

 

If my response helped you kindly mark this as helpful.

Thanks,

Mahesh.

WillieW
Tera Expert

Try the following example script in Scripts - Background, to see when the next Wednesday is:

 

var myDate = new GlideDateTime();
for (i = 0; i < 7; i++) {
	var weekDay = myDate.getDayOfWeek();
	gs.info(myDate + ', day of week: ' + weekDay);
	if (weekDay == 3)
		break;
	myDate.addDays(1);
}
gs.info(myDate + ' is Wednesday.');

Thank you I found the solution already