Error on Duration Variable

yoli1
Tera Contributor

hello team, i need to show error message if time spent is >24h but with UI policy it doesn't work any help?

yoli1_0-1700148260971.png

 

yoli1_1-1700148308948.png

It only work if i put a number higher that 1 in th Days part

 

1 REPLY 1

Kristen Ankeny
Kilo Sage

I would suggest using GlideDuration and GlideDateTime to achieve this. Here is an example:

 

Client script:

var getComparison = new GlideAjax('IncidentUtils2');
getComparison.addParam('sysparm_name','validateDuration');
getComparison.addParam('sysparm_dur', newValue);
getComparison.getXMLAnswer(compare);

function compare(answer){
	alert(answer);
}

 

Script include:

validateDuration: function(){
	var longer = false;
	var dur = this.getParameter('sysparm_dur');
	var durObj = new GlideDuration(dur);
	var durVal = durObj.getValue();
	var durDateTime = new GlideDateTime(durVal);
	var durValue = durDateTime.getNumericValue();
	var aDay = 24 * 60 * 60 * 1000;
	if(durValue > aDay){
		longer = true;
	}
	return longer;
},