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.
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 fromDonna 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…
Xrm.Page.getAttribute("actualdurationminutes").setValue(null);
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…
Xrm.Page.getAttribute("scheduledend").setValue(new Date());
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.
No comments:
Post a Comment