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-16-2017 05:41 AM
The same script is working for me, you would give wrong variable names, please verify.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
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','');
}
}
//Type appropriate comment here, and begin script below
}
Hope its onchange client script and you have selected the variable as date.
Please provide your code to review and proceed further.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2017 05:53 AM
Hi Balaji,
u_date is the name of the date/time variable that is being selected. Can I confirm that I only needed to amend the variable name in line 5 and the same in line 19 or was there something else that I was missing?
Is there any other setup required in order to get GlideAjax to work as I'm having trouble on another question where some has suggested and given me code for a GlideAjax that is also not working?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2017 06:47 AM
I can see the script is not active sate, active is false, make it true.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2017 02:08 AM
Hi Sam,
Did you tried my code by making client script Active true.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2017 04:16 AM
Hi Balaji,
I have tried with it set to active but it still on shows the message of the cdt variable, but does not warn of a future date and does not clear the field. I've added below the client side as I have it set and the script includes, not sure what is the issue.
