How to stop a stop an catalog task form closing the catalog task until the date is met on that task variables

ramya8
Kilo Contributor

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

1 ACCEPTED SOLUTION

Dan H
Tera Guru

Hi,

You can create a business rule for this.

See the following:

find_real_file.png

 

 

find_real_file.png

 

(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

View solution in original post

5 REPLIES 5

Hi @ramya have you got any follow up queries that I can help with? If not would you consider marking my answer as correct? 

 

thanks