- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2019 04:53 PM
I have a Select box field "Typeofinterface_interface" were we have 2 choices :"New" & "replacement" for that and a Date Field :" lis_golive_date ."
When user select New in the choice , if the user enter date, Date cannot be less than 90 days from today it should not submit the value and show an error
if Replacement is selected in the select box ,if the user enter date ,Date cannot be less than 30 days from today, it should not submit the value and show an error.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2019 11:57 AM
Hi,
Make the golive date field mandatory and write a onchange client script on it.
You might have to write a script include to do the date validations. Here is the link whih could help you.
https://community.servicenow.com/community?id=community_question&sys_id=82fd87addb9cdbc01dcaf3231f9619cb
if(g_form.getValue("u_type_of_interface")=="new") {
//write our logic for data comparison of
}
} else if (g_form.getValue("u_type_of_interface")=="replacement") {
//write our logic for data comparison of
}
Kindly mark the answer as correct/helpful if this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2019 11:57 AM
Hi,
Make the golive date field mandatory and write a onchange client script on it.
You might have to write a script include to do the date validations. Here is the link whih could help you.
https://community.servicenow.com/community?id=community_question&sys_id=82fd87addb9cdbc01dcaf3231f9619cb
if(g_form.getValue("u_type_of_interface")=="new") {
//write our logic for data comparison of
}
} else if (g_form.getValue("u_type_of_interface")=="replacement") {
//write our logic for data comparison of
}
Kindly mark the answer as correct/helpful if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2019 04:34 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2019 11:20 PM
Hi,
put your clearValue after the alert lines of code.
Regards,
Munender

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2019 11:49 PM
Hi Kam,
you can do this with client script as well. I have written this in my development instance and it is working fine. Kindly check the field names in the script as correct it as per your code.
Create a change client script on golive date as per the screenshot below.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var selectedDateNum = getDateFromFormat(newValue, g_user_date_format); //This gives the selected date
if(g_form.getValue("u_type_of_interface")=="New") {
var ninety_days =129600; //90 days in minutes
var ninety_days_date = new Date(new Date().getTime() - ninety_days*60000);
var ninety_days_dateStr = formatDate(ninety_days_date, g_user_date_format);
var ninety_days_dateNum = getDateFromFormat(ninety_days_dateStr, g_user_date_format);
if(selectedDateNum < ninety_days_dateNum) {
g_form.showErrorBox("u_golive","Selected date cannot be less than 90 days",true);
}
g_form.addInfoMessage("----Ninety date Num:"+ninety_days_dateStr+"----"+ninety_days_dateNum+"---selected date num: "+selectedDateNum);
} else if (g_form.getValue("u_type_of_interface")=="replacement") {
var thirty_days = 43200;// 30 days in minutes
var thirty_days_date = new Date(new Date().getTime() - thirty_days*60000);
var thirty_days_dateStr = formatDate(thirty_days_date, g_user_date_format);
var thirty_days_dateNum = getDateFromFormat(thirty_days_dateStr, g_user_date_format);
if(selectedDateNum < thirty_days_dateNum) {
g_form.showErrorBox("u_golive","Selected date cannot be less than 30 days",true);
}
g_form.addInfoMessage("Thirty days date: "+thirty_days_dateStr+"--"+thirty_days_dateStr+"---"+thirty_days_dateNum+"---selected date num: "+selectedDateNum);
}
}
Mark the answer as correct and helpful once this works for you.