- Back to Home »
- Set Default Activity Values – Duration, Date & Time
Hi All,
Ok, so first of all apologies for going quiet over the past few months! (Again!). I have just delivered the biggest CRM project that Chorus IT has ever delivered! This has been a huge success (with plenty lessons learned also!). Customer happy, seeing real tangible value and really excited about how MS Dynamics CRM 2011 is going to revolutionise their business.
As part of the development process, i have come across numerous interesting bits of JavaScript etc. that have helped me overcome certain issues and now we are coming to the conclusion of the project i will be blogging these over the coming weeks. I will also be thanking (if i can remember) those whose blog/tweets helped me come to the solutions i used along the way…
So, to begin… Setting Default Activity Values – Duration, Date & Time.
The system we built for our client is being heavily used to record activities for large sales teams. With a target of 100 calls a day in mind, any little pieces of data entry we could shave off would help hugely. One of these was the fact that every time they made a phone call they had to enter the duration (which on average was 2 minutes") and set the date and time to the current date and time.
Duration:
This was no where near as easy as i expected it to be. As you know, the duration field displays as an option set (dropdown) of values. As such you would think it would be easy to add values to this…………not so! This field is in fact a “Whole Number” field!After very briefly considering editing aspx files etc, stumbled across a comment from Donna Edwards MVP that noted the fact that you can enter a numerical value in here. This got me thinking, rather than add the option to the list, could i simply populate it via JavaScript and allow the field to do its thing and display it correctly?
It worked!
I used the following JavaScript to populate the value (using a Whole Number of course) and had the following results…
Date & Time
In contrast with the above, this was much easier than i thought. I found a post of the website of the legendary Sonoma Partners that dealt with this for the specific circs I was looking for. It utilises the JavaScript Date() function to retrieve the current date and time and populate this in the relevant field as follows with the following results…Only OnUpdate…
The only drawback to auto-populating these during the OnLoad event is that it will, of course, fire every time the page is loaded. This can be got around by referencing the form type when firing the JavaScript OnLoad as follows...function datetime()
{
var CRM_FORM_TYPE_CREATE = 1;
var CRM_FORM_TYPE_UPDATE = 2;
switch (Xrm.Page.ui.getFormType())
{
case CRM_FORM_TYPE_CREATE:
Xrm.Page.getAttribute("actualdurationminutes").setValue(null);
Xrm.Page.getAttribute("scheduledend").setValue(new Date());
break;
case CRM_FORM_TYPE_UPDATE:
// do nothing
break;
}
}
Hey presto! This meant that on creation of a phone call activity the script runs but not on any other occasion.
Hope this helps and stay tuned for some more interesting bits to come!
Thanks
xRM Consultant
Did you notice when you 'add' values that way into the duration field it doesn't really add it. It just sets it as a default and it's gone as soon as you're about the select another value. It may serve your purpose, but I have a list of values I have to add and none of them are not going to be the default value. Otherwise nice post! )
ReplyDeleteDoes this code still work on CRM 2016 Online?
ReplyDelete