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 04:01 AM
Hi Shloke,
I've also been trying Balaji's suggestion further up but can't seem to get either to work, have you any further suggestions?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2017 06:06 AM
Hi Sam,
For this you need to Write Script Include and Call that script Include in onChange Catalog Client Script on record producer.
Script Incldue:
var DateValidation = Class.create();
DateValidation.prototype = {
checkingFutureDate: function() {
return (gs.dateDiff(gs.nowDateTime(),this.getParameter('sysparm_startDate'),true));
},
type: 'DateValidation'
};
Catalog Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.hideFieldMsg("date variable");
var test = new GlideAjax('DateValidation');
test.addParam('sysparm_name','checkingFutureDate');
test.addParam('sysparm_start_date',newValue);
test.getXMLWait();
var answer = test.getAnswer();
if(answer < 0 )
return true;
g_form.showFieldMsg("date variable","Date Should not be a Future Date");
return false;
}
If this is Helpful Please Hit that helpful to you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2017 07:22 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2017 09:47 PM
Hi Sam,
I saw the client script you are calling Script include in GlidaAjax but the is Different, Can you please change the name try it once again.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.hideFieldMsg("u_date");
var test= new GlideAjax('CDLDateValidation');
test.addParam('sysparm_name','checkingFutureDate');
test.addParam('sysparm_date',newValue); // Hi Sam can you check it script include this parameter is Correct or not.
test.getXMLWait();
var answer = test.getAnswer();
if(answer < 0 )
return true;
g_form.showFieldMsg("u_date","Date and Time of Admission should not be in future date.","error");
return false;
//Type appropriate comment here, and begin script below
}
If this is Helpful Please Hit that helpful to you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2017 01:38 AM
Hi Pavan,
I've checked the script include and client script, now as below, however it is still showing the message even when the date is not in the future?
Script Includes:
var CDLDateValidation = Class.create();
CDLDateValidation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkingFutureDate: function() {
return (gs.dateDiff(gs.nowDateTime(),this.getParameter('sysparm_Date'),true));
},
type: 'CDLDateValidation'
});
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.hideFieldMsg("u_date");
var test= new GlideAjax('CDLDateValidation');
test.addParam('sysparm_name','checkingFutureDate');
test.addParam('sysparm_date',newValue);
test.getXMLWait();
var answer = test.getAnswer();
if(answer < 0 )
return true;
g_form.showFieldMsg("u_date","Date and Time of Admission should not be in future date.","error");
return false;
}