- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2017 11:19 AM
Hi all,
can any give me a proper explanation for my query , i have created two fields one is start date another is end date both field type are date .i want to set start date
user can only able to select present or future date but less than end date. and end date should be greater than start date. how to do that please let me know as soon
as possible .
Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2017 11:31 AM
Hi Sai,
This is exact same thing we do in change_request form for planned start and end date.
This can be achieved by OnSubmit client script on the table you want to validate on. I guess you can use same script what we have in 'Planned Start/End Date Validation':
https://<instance_name>.service-now.com/sys_script_client.do?sys_id=a99629f8ef011100521155aef5c0fb72
If you cant find this script let me know I can paste it.
Thanks
Shruti
If the reply was informational, please like, mark as helpful or mark as correct!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2017 11:31 AM
Hi Sai,
This is exact same thing we do in change_request form for planned start and end date.
This can be achieved by OnSubmit client script on the table you want to validate on. I guess you can use same script what we have in 'Planned Start/End Date Validation':
https://<instance_name>.service-now.com/sys_script_client.do?sys_id=a99629f8ef011100521155aef5c0fb72
If you cant find this script let me know I can paste it.
Thanks
Shruti
If the reply was informational, please like, mark as helpful or mark as correct!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2017 11:07 PM
hi shrythi i can't find script can you add here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2017 11:15 PM
Hi Sai,
Here is the OOB script, you should be able to user similar script with some modifications here and there by updating your field names. Your script will be on your custom table.
========START======
function onSubmit() {
var startDate = g_form.getValue("start_date");
var endDate = g_form.getValue("end_date");
var format = g_user_date_time_format;
if (startDate === "" || endDate === "")
return true;
// get date strings into a number of milliseconds since 1970-01-01
var startDateMs = getDateFromFormat(startDate, format);
var endDateMs = getDateFromFormat(endDate, format);
if (startDateMs < endDateMs)
return true;
g_form.clearMessages();
// 0 from "getDateFormat" means an invalid date string was passed to it
if (startDateMs === 0 || endDateMs === 0) {
if (startDate === 0)
g_form.addErrorMessage(new GwtMessage().getMessage("{0} is invalid", g_form.getLabelOf("start_date")));
if (endDate === 0)
g_form.addErrorMessage(new GwtMessage().getMessage("{0} is invalid", g_form.getLabelOf("end_date")));
return false;
}
if (startDateMs > endDateMs) {
g_form.addErrorMessage(new GwtMessage().getMessage("{0} must be after {1}", g_form.getLabelOf("end_date"), g_form.getLabelOf("start_date")));
return false;
}
}
======END=====
Let me know if it work for you or if you have any question.
Shruti