6.06.2006

More About Client-Side Scripting in CRM 3.0: Showing The Day In Date Fields in List Views

Since I'm not a developer by training, some of the coolest things I like to do with CRM involve using jscript on the client side. These are greate ways to customize CRM that don't require deep knowledge of programming, yet they can be very powerful as well.

With CRM 3.0 we are able to add script to three events for CRM forms: OnLoad, OnSave and OnChange.

This is also a source of frequent questions that I receive from my readers. So if you are looking for some guidance on creating your own scripts for Microsoft CRM, let me direct you first to the best resource: the SDK. You can view complete samples for all three events online at MSDN. The sample that gives you the most useful information, I think, is the OnSave sample.

Here's an example of a client-side script I wrote today for a customer of mine. Their CSRs wanted to be able to see, in list views, the time and date they set in the Follow Up By field on the case form, as well as the day of the week. While you can set the Follow Up By field to show the date and time on the form, this column doesn't display the weekday in views and associated views. So I added a simple custom field called new_duedate to the form and then put this script in the OnSave event:

varstrDueDate;
{
strDueDate=crmForm.all.followupby.DataValue.toLocaleString();
crmForm.new_duedate.value=strDueDate;
}

So, first the script declares the strDueDate variable, then it sets that variable as whatever the user has set the followupby date and time to be. The .toLocaleString() part converts the date into something a little more friendly to read than the UTC time format, though both the UTC string and the LocaleString contain the weekday. And lastly, the script sets my custom field's value to be whatever is in strDueDate.

I placed my custom field new_duedate on the bottom of the last tab of the case form where it would be out of the way. (You could also use some script in the OnLoad event that would set the display for this field to none so that it isn't visible at all). But remember, the field needs to be on the form, because this is client-side scripting. I also made the field read-only by double-clicking it after placing it on the form and setting it to locked. Next, I set the dependencies in the OnSave event dialog to include the new_duedate and followupby fields.

I added this custom field to the various views for cases, and voila, now users can see the day, date, and time that their cases are due.



Starting with an easy sample like this, I hope you can build upon it and come up with some creative ways to solve problems and extend the functionality of your CRM implementation. If you do, share them here!

1 comments:

Unknown said...

Hi Matt,

Excellent bit! I installed the mobile crm 3.0 client for one of my customers and the date field would not show. Using your code bit I filled a text field with the date tolocalstring and this field will show beautifully! Many thanks Aad

 
ICU MSCRM © 2004-2009