- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2019 05:39 AM
We have a requirement that checks the start date field to see if it is within 30 days prior or less.
For example:
If user selects 11/9/2019 it would fail, 11/10/2019 is fine and any date after is fine.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2019 06:14 AM
I was able to get it.. i dug down on an existing code and saw it went ot a script include. which i was able to find the function for getDateTimeBeforeNow and edited a script
//Checks to make sure start date inputted is not before today's date
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var cdt = g_form.getValue('start_date'); //First Date/Time field
var dttype = 'day'; //this can be day, hour, minute, second. By default it will return seconds.
var ajax = new GlideAjax('ClientDateTimeUtils');
ajax.addParam('sysparm_name','getDateTimeBeforeNow');
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 > 30){
alert("Start date cannot be more than 30 days from todays date.");
g_form.clearValue('start_date');
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2019 05:44 AM
Hi Mattrom,
Are you looking to do this client side or server side?
Regards,
Tudor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2019 05:50 AM
Catalog client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2019 05:45 AM
Hi Matt,
So you are saying any value which is beyond 30 days before now should show error.
you can use UI policy with condition as start date is before 30 days from now
start date relative on or before 30 days from now
in execute if script have this script
function onCondition() {
alert('Date must not be beyond 30 days prior to now');
g_form.clearValue('start_date');
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2019 05:50 AM
I tried this but nothing happens