- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2022 05:00 AM
Hi,
You can use onChange client script on the required field and write the code to check if the user is entering the past date.
Please mark correct/helpful based on impact.
Regards,
Bharath kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2022 12:27 AM
Hi Gayathri,
Create onChange Client Script on Field u want to change.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var currentDate = new Date(); //Current Date
var selectedDate = new Date(g_form.getValue('u_date_field')); //Date field value
if (currentDate.getTime() >= selectedDate.getTime()) {
//Past Date on Date field should thrown an error near field
g_form.showFieldMsg('You can not select a Past Date');
return false;
}
}
Shakeel Shaik 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2022 11:16 AM
Hi Gayathri
If my above response is helpful, then Please mark as Correct Answer/Helpful.
If you have any queries, let us know.
Thanks 🙂
Shakeel Shaik 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2024 10:05 PM - edited 05-06-2024 10:06 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2022 12:26 AM
Hi,
Try Below...It works.
Client Script : Onchange Client Script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var udt = newValue;
var ga = new GlideAjax("GetCurrentDateAndTime");
ga.addParam('sysparm_name', 'GetDate');
ga.addParam('sysparm_get_date', udt);
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == '5') {
g_form.setValue('date_field_name', "");
return false;
}
}
}
Script Include
var GetCurrentDateAndTime = Class.create();
GetCurrentDateAndTime.prototype = Object.extendsObject(AbstractAjaxProcessor, {
GetDate: function() {
var getNum = this.getParameter('sysparm_get_date');
var nd = new GlideDateTime();
if (getNum > nd) {
return 5;
},
type: 'GetCurrentDateAndTime'
});