Wednesday, August 4, 2010

Set a Default Date in Dynamics CRM 4.0 Using JavaScript

This blog will demonstrate how to set a default due date for the Phone Call entity in Dynamics CRM 4.0 by using a little bit of JavaScript.

T0 start go to Settings-->Customization-->Customize Entities. Scroll down to Phone Call and edit it by double-clicking or selecting More Actions and Edit from the toolbar.


Next, select Forms and Views and edit the Form. Select Form Properties and click the Edit button for the OnLoad Event. Copy the following code into the editor and click OK.

var CRM_FORM_TYPE_CREATE = "1";
var DUE;
var TODAY;

// Only make these changes when the form is opened in Create mode.
if (crmForm.FormType==CRM_FORM_TYPE_CREATE)
{
// Get today's date.
TODAY = new Date();

DUE = TODAY.setDate( TODAY.getDate());
crmForm.all.scheduledend.DataValue = DUE;
}




Now let's test our work by selecting Preview and Create Form. You will notice that the default value for Completed Date is now the current date and time. Note that I changed the "Due" to "Completed" date on the form editor.





No comments:

Post a Comment