Date/Time Field Restriction Record Producer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2017 08:18 AM
Hi All,
I have a date/time field on a record producer asking when the incident first occurred.
I have seen that the only way yo restrict this so people cannot add a date in the future is to have a script which validates this between the current date and the date selected when the field changes and then have a pop up message to warn the user.
I'm just not sure on how to script this?
Any help is greatly appreciated.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2017 08:44 AM
You can develop catalog client script for your record producer to implement validation for dates.
Please refer below post which will be helpful to you.
Date comparsion and validation within Catalog Items.
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2017 08:44 AM
I think this is one of the best documented community posts on date/time validation on the client side.
Client Script Date/Time Functions
This should answer all your questions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2017 09:19 AM
Hi Nathan,
Your code should be some thing like below
var cdt = g_form.getValue('date'); //First Date/Time field
var dttype = 'minute'; //this can be day, hour, minute, second. By default it will return seconds.
alert(cdt);
var ajax = new GlideAjax('ClientDateTimeUtils');
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 >0)
{
alert('date should not be future');
g_form.setValue('date','');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2017 07:31 AM
Hi Sam,
You can try my code(above), its working.
we are using oob script include ClientDateTimeUtils.
