The following is the code i have written & getting the error on form load "Unhandled Exception: System.ServiceModel.FaultException`1" & getting error "Cannot read property 'setValue' of null" on field load
function Experience()
{
var sDate = Xrm.Page.getAttribute("new_startdate");
var eDate = Xrm.Page.getAttribute("new_enddate");
if (typeof (sDate) != undefined && sDate != null && typeof (eDate) != undefined && eDate != null)
{
var startDate = new Date(Xrm.Page.getAttribute("new_startdate").getValue());
var endDate = new Date(Xrm.Page.getAttribute("new_enddate").getValue());
if(endDate < startDate )
{
alert("End date should not be less than Start date.");
}
else
{
var currentDate = new Date();
var difference = Math.floor(endDate.getTime() - startDate.getTime());
var days = ((difference % 31536000000) % 2628000000)/86400000;
var months = (difference % 31536000000) / 2628000000;
var years = difference / 31536000000;
var result = (Math.floor(years) + "." + Math.floor(months));
Xrm.Page.getAttribute("new_totalexperince").setValue(parseFloat(result));
}
}
}