How to pull asset warranty expiration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2019 05:49 AM
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;
}
}
- Labels:
-
Best Practices
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2019 06:20 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2019 06:20 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2019 06:35 AM
what if I utilize glidedate()?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2019 06:43 AM
we can use glidedate() function in server side only not in client scripts.
Write Script Include and call it in client script using GlideAjax