Trying to Calculate Days remaining
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2018 09:47 AM
All,
I'm trying to create a client script or business rule that calculates the difference of a Warranty Expiration Date and the current date to determine a "Number of Days remaining" on the warranty.
I found this script in community to modify, but I'm still missing something.
function onChange(control, oldValue, newValue, isLoading) {
var strt = g_form.getValue(warranty_expiration); //set this as current warranty date
var end = new Date(now.getFullYear(), now.getMonth(), no.getDate()); //This retrieves the current date
var ajax = new GlideAjax('AjaxDurCalc');
ajax.addParam('sysparm_name','durCalc');
ajax.addParam('sysparm_strt',strt);
ajax.addParam('sysparm_end',end);
ajax.getXMLWait();
var answer = ajax.getAnswer();
g_form.setValue('u_days_of_remaining_warranty', answer);
}
Below is an error that is received.
Any help is appreciated.
Jason
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2018 05:59 AM
Ravi,
Tried this, but no success. I do have it as a string value. Does this need to be duration?
Thanks.
Jason

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2018 09:59 AM
Did you try this?
(function executeRule(current, previous /*null when async*/) {
var start = new GlideDateTime();
var end = new GlideDateTime();
end.setValue(current.warranty_expiration);
// Duration in days
var dur = gs.dateDiff(start, end,false);
gs.addErrorMessage('This is the Duration:'+dur.split(' ')[0]);
current.u_days_of_remaining_warranty =dur.split(' ')[0];
})(current, previous);
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2018 08:45 PM
Can you change the above business rule type from "After update" to "After Query" and try ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2018 08:46 PM
Can you change the above business rule type from "After update" to "After Query" and try ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2018 08:50 PM
Can you add the info message to get the "days" value from the business rule and let me know?