Task 1 – ITSM : Check if the current time is greater than start date time and smaller than end date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Requirement: Check if the current time is greater than start date time and smaller than end date time. We assume here start date time and end date time are two Date/Time fields in a form.
Solution:
1. Create Fields (if not already present)
On your table:
start_date_time→ Type: Date/Timeend_date_time→ Type: Date/Timetimecheck→ Type: True/False
2. Create Before Business Rule
Navigation:System Definition → Business Rules → New
Set:
When: Before
Insert: ✔
Update: ✔
3. Script
Paste this in Advanced → Script
var now = new GlideDateTime();
var start = new GlideDateTime(current.start_date_time);
var end = new GlideDateTime(current.end_date_time);
if (now.getNumericValue() > start.getNumericValue() &&
now.getNumericValue() < end.getNumericValue()) {
current.timecheck = true;
} else {
current.timecheck = false;
}
})(current, previous);
4. How It Works
GlideDateTime()gets current system time.getNumericValue()converts dates into milliseconds for accurate comparison.Logic:
start < now < end → trueotherwise → falseBecause it's Before BR, value is set before record saves.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
so what's the question?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
This was helpful task @YashwanthV18760 !
