Compare current date time with a glide_date_time field value and when current date time > field value then perform some tasks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2022 10:36 AM
Custom glide date time field "Deadline".
I want to write a script which can compare the current date time value with the value in field "Deadline" and as soon as current date time value > Deadline, change some other field values.
What would be the best way to achieve this? Scheduled job or something else?
While comparing the current date time value I think it should take instance time zone and not some user, how to do that? Please suggest.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2022 08:37 AM
Hey Chandler,
Yes a Scheduled Job that runs periodically and performs that check would be the best way to go.
You can then write some server script that compares the current date with your Deadline date to see if it is greater (i.e has passed), you can also set the TimeZone of that Date if required.
// Get the system time zone. This property may be blank so double check.
var tz = gs.getProperty("glide.sys.default.tz");
// Or get the users timezone.
var tzU = gs.getSession().getTimeZone();
// The current Datetime in the system timezone.
var gdtNow = new GlideDateTime();
gdtNow.setTZ(tzU);
// Your Deadline Value
var gdtDeadline = new GlideDateTime('2023-05-04');
if (gdtNow > gdtDeadline) {
gs.addInfoMessage('Deadline has passed.');
} else {
gs.addInfoMessage('Deadline has not passed.');
}
Hope this helps.
Please mark the answer correct or helpful if it aided in solving your issue, thanks!