The CreatorCon Call for Content is officially open! Get started here.

How to pull asset warranty expiration

mdjoseph12
Giga Contributor

The script below should be pulling in the warranty expiration and comparing it to the current date but I continue to get undefined for the warranty expiration date

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}
	var serial = newValue;
	var warranty = warrantyDate(serial);
	var today =  new Date();
	var manufacturer = g_form.getDisplayValue('model_manufacturer');
	var contact = g_form.getDisplayValue('company_phone');
	var company = g_form.getDisplayValue('company');
	
	alert(warranty);

	if(today < warranty) {
		
		alert("This item may be under warranty. Please contact " + company + " at " + contact+".");
		g_form.clearValue('serial_no');
	}
	
	function warrantyDate(serial_no) {
		var warranty;
		
		var gr = new GlideRecord("alm_asset");
		gr.addQuery("serial_number", serial_no);
		gr.query();
		while (gr.next()) {
			
			warranty = gr.getDisplayValue('warranty_expiration');
			
		}
		
		return warranty;
	}
	
	
}
7 REPLIES 7

Chandu Telu
Tera Guru

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var serial = newValue+"";
var warranty = warrantyDate(serial);
var today = new Date();
var manufacturer = g_form.getDisplayValue('model_manufacturer');
var contact = g_form.getDisplayValue('company_phone');
var company = g_form.getDisplayValue('company');

alert(warranty);

if(today < warranty) {

alert("This item may be under warranty. Please contact " + company + " at " + contact+".");
g_form.clearValue('serial_no');
}

function warrantyDate(serial_no) {
var warranty;

var gr = new GlideRecord("alm_asset");
gr.addQuery("serial_number", serial_no);
gr.query();
while (gr.next()) {

warranty = gr.getDisplayValue('warranty_expiration');

}

return warranty;
}

 

Change the highlighted line and check it

 

Please make this answer is correct if i answer your question

Chuck Tomasi
Tera Patron

The short answer that Date() on the client side is going to return a date in the format of

Tue Apr 30 2019 06:19:30 GMT-0700

While your date/time field from the database is in YYYY-MM-dd hh:mm:ss

Your comparison is off. I'm looking to see if there is a client side script that will offer the Date() output in a form at we can do an equal comparison.

what if I utilize glidedate()?

we can use glidedate() function in server side only not in client scripts.

Write Script Include and call it in client script using GlideAjax