If you spend a lot of time creating activities in Microsoft Dynamics CRM and would like a simple way to auto-populate a date field, here’s how:
First, decide what field you’d like to populate. In this example, we focus on the due date field of the phone call entity. Second, determine when you would like the field to populate. Will it only be when creating new entities, modifying existing ones or both? In this case, we’ll set the due date field on the creation of the phone call entity only.
if(Xrm.Page.ui.getFormType() == 1)
var dueDate = Xrm.Page.data.entity.attributes.get("scheduledend");
var now = new Date();
var endDate = new Date().setDate(now.getDate()+7);
Above, you’ll notice that our whole function is wrapped in an if statement that is comparing the FormType. This is how we determine if the form is for a new entity or the modification of an existing one. On the next line, you’ll notice us getting a reference to our due date field (in this case, its schema name is scheduledend). Later, we’ll use this to set the date we create.
The next two lines are where we create a Date (now) that matches the current date and time and then create a new date that exists exactly seven days in the future.
Finally, we assign our end date to the due date field we referenced earlier. There you have it, a simple and quick way to remove a tedious task and effected standardization in your process.