CRM 2011: Set Due Date to today and Due Time to 08:00 AM by default

Hello everyone…

Recently I was asked a question:
Can we load current date and time (8 AM default) to Due field in activities in Microsoft Dynamics CRM 2011?
I got the solution… yeah!!

For this you need to edit the activity (Task/Phone Call/Fax/Email/etc.) entity and put a JavaScript in OnLoad event of the entity form.

My First try was to access both date and time through HTML DOM with very easy JavaScript code…

document.getElementById("dateInput").value = currentDate;
document.getElementById("timeInput").value = "08:00";

But, it created a problem; when the date field was edited by the user, the time would change to 00:00 by default. I searched many blogs and finally found an attribute called scheduledend which can be accessed through Xrm.Page object and getAttribute() method. Just need to set a JavaScript date and you have the values desired in Due Date and Time fields.

Here is the script I wrote to populate date and time:

var d = new Date();
var date = new Date(d.getFullYear(), d.getMonth(), d.getDate(), 8, 0, 0, 0);
Xrm.Page.getAttribute("scheduledend").setValue(date);

Here is the result when a new activity is created:

Cheers!!
Rikin Shah.

Advertisements

3 thoughts on “CRM 2011: Set Due Date to today and Due Time to 08:00 AM by default

  1. Hi Rikin,
    Gr8 Post..
    But can i just set Time.. and keep date feild for user to be filled in a date time field.

    Regards
    Jasveer

    • Hi Jasveer,

      I haven’t tried it yet. This would be a wild guess… But, Have you tried by directly removing dateInput by accessing it from HTML DOM once you have set the date and time from above code? Or if you found another solution do let me know.

      Thanks,
      Rikin

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s