Regarding onchange planned start date Validation in change Request
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2025 07:31 AM
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || !newValue) {
return;
}var changeType = gForm.getValue('type');
if (changeType.toLowerCase() === 'normal') {
var ga = new GlideAjax('ValidateStartDateUtils');
ga.addParam('sysparm_name', 'isFutureDateTime');
ga.addParam('sysparm_selected_date', newValue);
ga.getXMLAnswer(function(response) {
if (response === 'false') {
gForm.showFieldMsg('start_date', 'Start date must be in the future for Normal changes.', 'error');
gForm.setValue('start_date', '');
}
});
}
}this is client script
var ValidateStartDateUtils = Class.create();
ValidateStartDateUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isFutureDateTime: function() {
var selectedDate = this.getParameter('sysparm_selected_date');
if (!selectedDate) return false;
var selected = new GlideDateTime(selectedDate);
var now = new GlideDateTime();
return selected.after(now) ? 'true' : 'false';
}
});and script includes but it is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2025 07:39 AM - edited 05-13-2025 08:03 AM
Hi @LokeshwarRV
Try UI policy to achieve this requirement.
UI policy condition should be planned start date is after today.
Then in the scripts under 'Execute if false' add the below script.
g_form.clearValue('start_date');
g_form.showFieldMsg('start_date','Planned start date should be a future date','error');
Also, it should be g_form not gForm
Regards ,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2025 07:43 AM - edited 05-13-2025 08:24 AM
@LokeshwarRV - Can you try below -
1. Client Script
Type: onChange
Field: start_date
Table: Change Request (or your custom table)
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || !newValue) {
return;
}
var changeType = gForm.getValue('type');
if (changeType.toLowerCase() === 'normal') {
var ga = new GlideAjax('ValidateStartDateUtils');
ga.addParam('sysparm_name', 'isFutureDateTime');
ga.addParam('sysparm_selected_date', newValue);
ga.getXMLAnswer(function(response) {
if (response === 'false') {
gForm.showFieldMsg('start_date', 'Start date must be in the future for Normal changes.', 'error');
gForm.setValue('start_date', '');
}
});
}
}
> Note: Be sure the type field exists on the form and has a value like 'normal'.
2. Script Include
Name: ValidateStartDateUtils
Check: Must be client-callable
var ValidateStartDateUtils = Class.create();
ValidateStartDateUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isFutureDateTime: function() {
var selectedDate = this.getParameter('sysparm_selected_date');
if (!selectedDate) return 'false';
var selected = new GlideDateTime(selectedDate);
var now = new GlideDateTime();
return selected.after(now) ? 'true' : 'false';
}
});
> Important: Make sure the Script Include has:
Name: ValidateStartDateUtils
Client Callable: Checked (true)
Additional Notes
- The client script converts the date to a GlideDateTime-compatible ISO format before sending it to the server, avoiding parsing issues. Confirm that start_date field is a GlideDateTime type (not just date).
- Make sure the field names 'type' and 'start_date' exactly match your form field names.
- This client script should be attached to the onChange event of the start_date field.
- Temporarily add console.log(response); inside getXMLAnswer() callback to verify the response is received.
- The Script Include must be Client Callable to be accessible from GlideAjax. Ensure the Script Include is global or in the same application scope as your client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2025 08:13 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2025 08:20 AM
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || !newValue) {
return;
}
var changeType = g_form.getValue('type');
if (changeType.toLowerCase() === 'normal') {
var ga = new GlideAjax('ValidateStartDateUtils');
//alert("hello");
ga.addParam('sysparm_name', 'isFutureDateTime');
ga.addParam('sysparm_selected_date', newValue);
ga.getXMLAnswer(function(response) {
if (response === 'false') {
alert("Start date must be in the future for Normal changes");
g_form.clearValue('start_date');
g_form.showFieldMsg('start_date', 'Start date must be in the future for Normal changes.', 'error');
}
});
}
@LokeshwarRV Try this