Trying to Calculate Days remaining

jasonjones
Giga Contributor

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.

find_real_file.png

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.

find_real_file.png

Any help is appreciated.

Jason

41 REPLIES 41

You can use the string field in combination with my code in the BR. It would do the trick for you


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

I changed it to String and it didn't populate.


Jason

find_real_file.png

find_real_file.png

 

 

Change the variable name correctly in line8 in your script.

Should be u_days_of_remaining_warranty

 


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

As you can tell, I'm not a coder by trade.  Should it be current.u_days_remaining_on_warranty = dur();

 

Replace your 8th line with current.u_days_of_remaining_warranty = dur.getDayPart();


Please mark my response as correct and helpful if it helped solved your question.
-Thanks