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-23-2018 12:42 PM
ok. I see it now. Sorry.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2018 12:45 PM
and still no results.
Jason
(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 = GlideDateTime.subtract(start, end);
current.u_days_of_remaining_warranty = dur.getDayPart();
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2018 12:56 PM
Try changing code with this and let me know if you see any message on the top of your screen. Can you also share your when to run section of the BR
(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 = GlideDateTime.subtract(start, end);
gs.addErrorMessage('This is the Duration:'+dur.getDayPart());
current.u_days_of_remaining_warranty = dur.getDayPart();
})(current, previous);
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2018 01:20 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2018 01:23 PM
You don't have to check query select box. Did you see the message on the screen??
Please mark my response as correct and helpful if it helped solved your question.
-Thanks