- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2025 09:08 AM
My requirement : I have a field on the form as 'Due Date' and want to check if current date has past this due date or not when user opens the form
Accordingly, need to show infoMessage on the form.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2025 10:06 AM
you can use onLoad client script and compare like this
function onLoad() {
var nowDateTime = new Date().getTime();
var dueDate = new Date(g_form.getValue('due_date')).getTime();
if (dueDate < nowDateTime) {
g_form.addInfoMessage('Your message here');
}
}
Another way is to use UI policy
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2025 10:06 AM
you can use onLoad client script and compare like this
function onLoad() {
var nowDateTime = new Date().getTime();
var dueDate = new Date(g_form.getValue('due_date')).getTime();
if (dueDate < nowDateTime) {
g_form.addInfoMessage('Your message here');
}
}
Another way is to use UI policy
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2025 10:50 AM
One correction i missed to ask in.the original question
If current date is past the due date, I need to update a field on the form. So can you suggest a server side solution as well
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2025 07:29 PM
you can use a before update business rule and check this
var nowDateTime = new GlideDateTime().getNumericValue();
var dueDateTime = new GlideDateTime(current.due_date).getNumericValue();
if (dueDateTime < nowDateTime) {
current.u_field = 'your value';
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2025 10:20 AM
Hi @Snehal13 ,
create a display Business rule
with script
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
g_scratchpad.isPastDueDate = GlideDateTime.subtract(current.due_date.getGlideObject(), new GlideDateTime()).getNumericValue(); //replace due_date with your field name
})(current, previous);
replace due_date with your field name if required
create a client script of your requirement onLoad or onChange
I have created a onload client script for testing (use the scratchpad object to know if the due date has passed and directly display the message
function onLoad() {
//Type appropriate comment here, and begin script below
if (g_scratchpad.isPastDueDate > 0) {
g_form.addErrorMessage('already passed due date')
}
}
result
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya