- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2024 11:34 PM
Hi
i have a oob date field opened_at
when I use below code in onchange client script (onchange of preliminary action date field).
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2024 01:07 AM
Hi @vijay23,
You may try with the following on change client script.
Please mark my response as correct and helpful if it helped solved your question.
Thanks,
Rohit Suryawanshi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2024 11:52 PM
Hi @vijay23 ,
Please check the below:
https://servicenowguru.com/client-scripts-scripting/client-side-dates-in-servicenow/
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2024 12:54 AM
try :
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var openedDateStr = g_form.getValue('opened_at');
var openedDate = new Date(openedDateStr);
var preliminaryActionDate = new Date(newValue);
var todayDate = new Date();
todayDate.setHours(0, 0, 0, 0);
if (preliminaryActionDate < openedDate || preliminaryActionDate > todayDate) {
g_form.clearValue('u_preliminary_action_date');
g_form.showFieldMsg('u_preliminary_action_date', getMessage('preliminary_action_date.info.message'), 'error');
}
}
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2024 01:07 AM
Hi @vijay23,
You may try with the following on change client script.
Please mark my response as correct and helpful if it helped solved your question.
Thanks,
Rohit Suryawanshi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2024 04:16 PM
use the below code for
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var g_user_date_format = g_user_date_time_format.split(' ')[0]; // Extract only the date part
var g_user_time_format = g_user_date_time_format.split(' ')[1]; // Extract only the time part if present
var openedDate = new Date(getDateFromFormat(g_form.getValue('opened_at'), g_user_date_time_format));
var todayDate = new Date();
var preliminaryActionDate = new Date(getDateFromFormat(newValue, g_user_date_time_format));
if (isNaN(openedDate.getTime())) {
alert('Invalid opened_at date');
return;
}
if (isNaN(preliminaryActionDate.getTime())) {
alert('Invalid preliminary action date');
return;
}
if ((preliminaryActionDate < openedDate) || (preliminaryActionDate > todayDate)) {
g_form.clearValue('u_preliminary_action_date');
g_form.showFieldMsg('u_preliminary_action_date', getMessage('preliminary_action_date.info.message'), 'error');
}
}