IF condition to check whether "u_date" >= current date.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2022 05:44 AM
I need an IF condition in UI Action script to check whether "u_date" >= current date.
*u_date is Date field type.
Please let me know how to express it in the script in the simplest way.
Best Regards,
Aki
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2022 05:50 AM
Hi,
You can use something like below in the condition field
current.u_date >= new GlideDateTime()
-Anurag
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2022 05:55 AM
Hi,
something like this
new GlideDateTime(current.u_date).getNumericValue() >= new GlideDateTime().getNumericValue()
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2022 04:38 PM
Since u_date is a Date and not a DateTime field, would require to compare GlideDateTime().
"new GlideDateTime()" will return the current Date/Time and not the Date. That is, following will return something like "2022-01-26 00:10:00" instead of "2022-01-26 00:00:00". So, if the u_date is today, the if condition would return false because "new GlideDateTime()" will be greater.
var gd = new GlideDateTime();
gs.info(gd);
Taking this in account,
new GlideDateTime(current.u_date).getNumericValue() >= new GlideDateTime((new GlideDate).getValue() + ' 00:00:00').getNumericValue()

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2022 04:53 PM
On second thought, it would be little bit easier to write as below:
new GlideDateTime(current.u_date + " 23:59:59").getNumericValue() >= new GlideDateTime().getNumericValue()