Add days to date using JavaScript in Dynamics CRM

This blog post is related to Datetime field in CRM. In many scenarios, we want to recalculate the date field value in Dyanamics CRM by adding days to it. The below JavaScript function is useful in that condition :

//Function to add days to date

function addDays(date, days) {
var result = new Date(date);
result.setDate(result.getDate() + parseInt(days));
return result;
}

//Recalculate date field value

function recalculateDateFieldValue() {
var date= Xrm.Page.getAttribute(“datefieldname”).getValue();

if (firstemaildueDate != null) {
Xrm.Page.getAttribute(“datefieldname”).setValue(addDays(date, 42));
}
}

we can recalculate date field value by adding days as per our needs by checking conditions. Hope this helps.!

 

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s