-O-
Kilo Patron

You should not be using date display values on server side - it just complicates things while adding nothing to the outcome. If you insist, you should on one hand use .getDisplayValueInternal() instead on the other hand use it throughout. It returns the date and time value in the system format.

All that also means you can't use new GlideDateTime (inquiryDate);: it expects inquiryDate to be the date and time in the system TZ (UTC by default), but it will most likely not be as the value has been obtained using a display value method - which returns the date and time in the current user's TZ.

That is why, just don't use the display value methods on server side.

Thank you Janos. This helps explain things for me and will be useful to come back to in the future!

You're most welcome 🙂

DrewW
Mega Sage

Try the below.  It should be doing everything in GMT.

Also why do you care if its open before you use the resolution date?  Why not just check if it has a value and if it does then use it?

(function executeRule(current, previous /*null when async*/) {

	if(current.u_inquiry_date){
		var startDate = current.u_inquiry_date.getGlideObject();
		var endDate = new GlideDateTime();
		if(current.getValue('u_state') != 'Open' && current.u_resolution_date){
			endDate = current.u_resolution_date.getGlideObject();
		}
		var dur = endDate.getNumericValue() - startDate.getNumericValue();
		//convert the answer from milliseconds to days
		var days = dur /  (1000*60*60*24);
		if(days < 1){
			days = 1;
		}
		current.u_resolution_time = days;
	} else {
		current.u_resolution_time = 0;
	}

})(current, previous);

View solution in original post

Hi Drew,

This (combined with Janos' response) helped me immensely! Thank you so much!

-Matt