- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2018 07:19 AM
Hi,
Please help me script. I have date field named startdate, but I need for users not to be able to select any date before 5 days from today.
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2018 08:44 AM
Here's my OnChange Client Script that calls the same Script Includes (with the original name however) requiring that a due date is greater than 5 days out (note it is in seconds):
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var cdt = g_form.getValue('due_date'); //First Date/Time field
var ajax = new GlideAjax('ClientDateTimeUtils');
ajax.addParam('sysparm_name','getNowDateTimeDiff');
ajax.addParam('sysparm_fdt', cdt);
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
//5 days out
if (answer < 431000)
{
alert('The lead time to process this request is 5 days.' + '\n' + 'If this is an urgent request please contact the Service Desk for assistance escalating this request.');
//alert('The date value cannot be before 5 days into the future. Please correct.');
//g_form.clearValue("due_date");
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2018 07:31 AM
Hii,
Refer the below link and you should be able to get the script
https://community.servicenow.com/community?id=community_question&sys_id=3d4b0321db9cdbc01dcaf3231f961935&view_source=searchResult
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2018 08:18 AM
Hi,
I tried to make use of what I think is the answer, but without luck. It doesn't work.
The bold characters below are the only ones I've modified.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var cdt = newValue; //The date field
var dttype = 'day'; //this can be day, hour, minute, second. By default it will return seconds.
/******** This Checks whether the selected date is in the Past or Not************************/
var ajax = new GlideAjax('ClientDateTimeUtils_New');
ajax.addParam('sysparm_name','getNowDateTimeDiff');
ajax.addParam('sysparm_fdt', cdt);
ajax.addParam('sysparm_difftype', dttype);
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer<-5){
alert("Start date can only be after 5 days from today.");
g_form.clearValue('startdate'); // Pass the variable name here
g_form.setMandatory('startdate', true);
}
}}
I have also created the script include, copied everything into it. Doesn't work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2018 08:44 AM
Here's my OnChange Client Script that calls the same Script Includes (with the original name however) requiring that a due date is greater than 5 days out (note it is in seconds):
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var cdt = g_form.getValue('due_date'); //First Date/Time field
var ajax = new GlideAjax('ClientDateTimeUtils');
ajax.addParam('sysparm_name','getNowDateTimeDiff');
ajax.addParam('sysparm_fdt', cdt);
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
//5 days out
if (answer < 431000)
{
alert('The lead time to process this request is 5 days.' + '\n' + 'If this is an urgent request please contact the Service Desk for assistance escalating this request.');
//alert('The date value cannot be before 5 days into the future. Please correct.');
//g_form.clearValue("due_date");
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2018 09:15 AM
Hi, Shane.
Thank you very much! It worked like a charm!