Iprompt.GIF"/api/data/v9.1/msdyn_richtextfiles(16DDA1DF-A3BD-436E-B1F3-FC8E374069A7)/msdyn_imageblob/$value?size=full">I am using Microsoft Dynamics CRM 2011 on prem.
I am trying to write some code to find the age of a record from created on to sold.
We DO NOT use the out of the box CRM 'close as won' or 'close as lost' fields.....
We use an option set called 'Sales Stage' with multiple options, one of which is the value of 'Sold'...
I am trying to say, when sales stage value is set to sold, calculate the days between Created On Date and the Sold Date (custom date field), and then put the number in a field called 'Pipeline Age' (whole number field). Here's my code :
function ageofrecord_onchange() {
var createddate = Xrm.Page.getAttribute("createdon").getValue();
var solddate = Xrm.Page.getAttribute ("new_soldtobankdate").getValue();
var salesstage = Xrm.Page.getAttribute("new_salesstagercd").getValue();
if (salesstage == 100000008) {
Xrm.Page.getAttribute("new_pipelineage").setValue(solddate - createddate);
}
}
I'm hesitant because I'm trying to take a date field and put the difference in a whole number field. Will this work or am I off here?