- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2022 12:17 PM
we have a requirement where when a task is assigned to a person and on the task variables there is a date field when the date field is set for 3/17/22 we should validate with the current date and should not allow closing the task until the date is met
function onSubmit() {
//Type appropriate comment here, and begin script below
var type = g_form.getValue('u_task_category');
var action = g_form.getActionName();
var state = g_form.getValue('state');
if ((action == 'close_task' || state == 3) && type == 'Finance-Input') {
var date = g_form.getValue('finance_target_date');
var ga = new GlideAjax('CatalogMain');
ga.addParam('sysparm_name', 'dateValidate');
ga.addParam('sysparm_newdate', date);
ga.getXML(getData);
}
function getData(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
return false;
}
}
Tried this code no luck can some one assist I'm new to servicenow
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2022 12:54 PM
Hi,
You can create a business rule for this.
See the following:
(function executeRule(current, previous /*null when async*/) {
var taskDate = current.u_finance_target_date;
var time = new GlideDateTime();
if(taskDate > time){
gs.addInfoMessage("The date on the task is later than the current date.");
current.setAbortAction(true);
}
})(current, previous);
Please mark my answer as Correct/Helpful based on impact
Regards,
Dan H
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2022 12:35 PM
Hi,
you don;t need to use GlideAjax here.
have a look at the following threads for date validation via client script in servicenow:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2022 12:54 PM
Hi,
You can create a business rule for this.
See the following:
(function executeRule(current, previous /*null when async*/) {
var taskDate = current.u_finance_target_date;
var time = new GlideDateTime();
if(taskDate > time){
gs.addInfoMessage("The date on the task is later than the current date.");
current.setAbortAction(true);
}
})(current, previous);
Please mark my answer as Correct/Helpful based on impact
Regards,
Dan H
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2022 02:01 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2022 02:06 PM
It will not matter how to task is closed, from UI action, from changing the state or any other way. The business rule will trigger.
Please mark my answer as Correct/Helpful based on impact
Regards,
Dan H