Jan 18 2008

Changing The Default Views In CRM 3.0 & CRM 4.0

One of the unusual quirks with Microsoft CRM 3.0 is the hard-coded default Views. For example, while in a Contact form and you click History, the default view is for “Last 30 Days”. This has been one of the most disliked features of CRM 3.0 and we are sad to report the same condition exists in the new CRM 4.0 version. The good news is we’re going to show you how to change these Views.

Let’s start with the CRM 3.0 method . The code we’re going to use was borrowed from Michael over at stunnware. He has a great explanation of how we build the code, but we’ll just get straight to the code and enhance it a little. Our adjustment will modify 3 related entities, Activities, History and Opportunities. For each one we will make the default View “All”.

Assuming it’s the Contact’s View that you want to alter, in the Customization area, open the Contact form. Go into the Form Properties and then the OnLoad event. Copy this text and paste it into the OnLoad window:

SetDefaultView = function(viewCombo, viewName) {
if (viewCombo.value != viewName) {
viewCombo.value = viewName;
viewCombo.FireOnChange();
}
}
areaActivityHistoryFrame_OnReadyStateChange = function() {
if (this.readyState == “complete”) {
var frame = document.frames(”areaActivityHistoryFrame”);
var viewCombo = frame.document.getElementById(”actualend”);
if (viewCombo.readyState == “complete”) {
SetDefaultView(viewCombo, “All”);
}
else {
viewCombo.onreadystatechange = function() {
if (this.readyState == “complete”) {
SetDefaultView(this, “All”);
}
}
}
}
}
areaOppsFrame_OnReadyStateChange = function() {
if (this.readyState == “complete”) {
var frame = document.frames(”areaOppsFrame”);
var viewCombo = frame.document.getElementById(”statecode”);
if (viewCombo.readyState == “complete”) {
SetDefaultView(viewCombo, “All”);
}
else {
viewCombo.onreadystatechange = function() {
if (this.readyState == “complete”) {
SetDefaultView(this, “All”);
}
}
}
}
}
areaActivitiesFrame_OnReadyStateChange = function() {
if (this.readyState == “complete”) {
var frame = document.frames(”areaActivitiesFrame”);
var viewCombo = frame.document.getElementById(”scheduledend”);
if (viewCombo.readyState == “complete”) {
SetDefaultView(viewCombo, “All”);
}
else {
viewCombo.onreadystatechange = function() {
if (this.readyState == “complete”) {
SetDefaultView(this, “All”);
}
}
}
}
}
loadArea(’areaActivityHistory’);
loadArea(’areaActivities’);
loadArea(’areaOpps’);
loadArea(’areaForm’);
document.frames(”areaActivityHistoryFrame”).document.onreadystatechange = areaActivityHistoryFrame_OnReadyStateChange;
document.frames(”areaActivitiesFrame”).document.onreadystatechange = areaActivitiesFrame_OnReadyStateChange;
document.frames(”areaOppsFrame”).document.onreadystatechange = areaOppsFrame_OnReadyStateChange;

Open a Contact record and verify that the 3 related entities are showing “All” as their default Views.
Now let’s discuss the CRM 4.0 version. Unfortunately the above code doesn’t work in 4.0 and will cause an error message to the user. The method we need to use is an unsupported modification but one we feel is very safe.

First, on your CRM 4.0 Server, make a copy of this file – “AppGridFilterContainer.htc”, from this folder location:

C:\Program Files\Microsoft Dynamics CRM Server\CRMWeb\_static\_controls\appgridfiltercontainer
(this is the default location, your installation may be different)

Now that we have a copy, we can safely modify the original file. Open AppGridFilterContainer.htc with notepad or wordpad. Near the bottom of the page, find these lines:

if(!IsNull(oCtrl.DataValue))
{
oCallback(oCtrl);

We are going to replace the 3 lines above with this code:

if(!IsNull(oCtrl.DataValue))
{
if(oCtrl.DataValue==”LastXDays;30” || oCtrl.DataValue==”NextXDays;30” || oCtrl.DataValue==”0”)
{
oCtrl.DataValue = “All”
RefreshGridView();
}
oCallback(oCtrl);

Make sure you delete your Temporary Files from Internet Explorer after making the change, otherwise the change will not take effect.

If you notice, all we’re doing is adding an “If” statement into the existing CRM 4.0 code. Although this modification is unsupported, it’s pretty benign.

Close the file and open a Contact record in CRM 4.0. The default View for the 3 related entities should be defaulted to “All”. If you receive an error message you can easily revert back to the original file you copied.

Enjoy the new View!

David Grant
Microsoft CRM Consultant
Unitek Microsoft CRM Services

20 Responses to “Changing The Default Views In CRM 3.0 & CRM 4.0”

  1. Ridhimaon 14 Feb 2008 at 2:27 am

    Hi David

    I tried pasting your code to change the default view of history, activities and opportunities to All. I have published the customizations and when I open a contact i see no change. Could you please advise me?

    Also is this a supported or unsupported customisation please?

    Regards
    Ridhima

  2. Unitek CRM Teamon 14 Feb 2008 at 5:31 pm

    Hi Ridhima,

    Are you trying this on CRM 3.0 or CRM 4.0?

    If 3.0, when the Contact window opens do you have an error showing in the status bar in the lower left corner?

  3. oriolon 20 Feb 2008 at 3:17 pm

    Thanks David!

    We thought that all areas use ’statecode’ but no, Activities and ActivityHistory are sorted by different attributes. If I didn’t have found your blog I can’t got the solution!

    see you

  4. Brianon 20 Feb 2008 at 8:09 pm

    I can’t get this to work in CRM 4.0. I modified AppGridFilterContainer.htc as instructed but it doesn’t have an effect. Has anyone got this working in 4.0?

  5. Brianon 20 Feb 2008 at 8:42 pm

    Actually, it does work. Watch out for those double quotes is you cut/paste from the web. May have to replace them with a true double quote in your text editor, that was my issue.

  6. mdoddon 29 Feb 2008 at 2:58 pm

    I has the same issue, too. The formatting of double quotes from blogs is a common “gotcha”. A recommendation is to put all code blocks using the Courier New font, which eliminates this issue.

  7. nitin dawareon 15 Apr 2008 at 2:45 am

    Hi David, For contact history it showing all, but for activities it still showing ‘next 30 days’ for ms crm 3.0

  8. Unitek CRM Teamon 15 Apr 2008 at 4:13 pm

    Hi Nitin,

    Make sure you 1. Checked the quotation marks (from previous posts) 2. Cleared your IE temp files if you’re using the v4 method.

  9. nitin dawareon 17 Apr 2008 at 12:37 am

    Thanks David, success, its really proved boon to solve urgent problem in one step hats off:)

  10. Pellon 09 May 2008 at 8:05 pm

    Very nice. I got caught on the quotes as well. How the heck do you guys find these solutions!

  11. Halldojoon 16 Jul 2008 at 3:40 pm

    Right first time posting here so completely new to me that xml tags are removed hehe..

    So trying again, please remove the earlier post.

    Easier way is to export the Entity (Contact or Account) Search for the View (f.e. “Active Accounts”) you want as default and edit the XML directly (Make backups).

    Make sure you are in the correct view when you are editing, as the name usually is at the bottom of the defenition of the view you searched for..

    Find this line above your result and set it as (After searching f.e. “Active Accounts”)

    ‘1′ Make it as default view
    ‘0′ Not default view

    Doing it this way you also have to find the previous default view and edit that as not being default, usually being in the case of accounts “My Active Accounts”.

    This ofcourse is completely unsupported.

    P.s. WTB preview 8)

  12. JBon 16 Jul 2008 at 10:25 pm

    I have a javascript method working in 4.0!

    Instead of registering the onreadystatechange event handler in the onload event, I override the onclick event of the navigation element and register the onreadystatechange handler there:

    if (document.getElementById(’navActivities’)!=null)
    document.getElementById(’navActivities’).onclick = function() {
    loadArea(’areaActivities’);
    document.frames(”areaActivitiesFrame”).document.onreadystatechange = areaActivitiesFrame_OnReadyStateChange;
    }

    The only additional code in the SetDefaultView function required is:
    document.frames(”areaActivitiesFrame”).document.getElementById(”AppGridFilterContainer”).RefreshGridView();

    Obviously change the frame and navigation element names depending on which related entity you’re working (I pass another parameter to the SetDefaultView function to handle the frame name).

    No editing the AppGridFilterContainer.htc file!

  13. Jeetuon 12 Aug 2008 at 1:22 pm

    Dear David,

    First of all thanks for sharing your code with us.

    I’m using CRM 3.0, and I’ve pasted your code in my application, but I’m getting the following error:-

    Line 261
    Char 24
    Error Invalid Character
    Code 0
    URL — something …..

    and

    Line 252
    Char 72
    Error Object Expected
    Code 0
    URL — something…..

    Please help me. If possible.

    Thanks in advance

    With Regards,

  14. Unitek CRM Teamon 12 Aug 2008 at 6:00 pm

    Hello Jeetu,

    I believe you need to correct the quotation marks after you copy & paste into CRM.

    When you see the quotes in the pasted code, manually delete them and type in new ones.

  15. Dougon 21 Aug 2008 at 5:31 pm

    Great Info!

    Running into an issue though…

    Doesn’t look like the changes are taking hold to my 4.0 implementation. I fixed the double quote issue and deleted my Temp Internet Files…Any other ideas what might be going on?

  16. Unitek CRM Teamon 21 Aug 2008 at 9:52 pm

    Hi Doug,

    If you needed to fix the quotation marks then you are using the CRM 3.0 method, not the CRM 4.0 method. The CRM 3.0 method will not work in CRM 4.0

    Did I misunderstand?

  17. Alberton 28 Aug 2008 at 1:35 pm

    hello,

    the code for the 3.0 version is running fine. However when I create a new contact or account for example, I get the yellow triangle at the bottom. I think this is because there is no historyFrame for new (unsaved) records… Is there a workaround?

  18. Unitek CRM Teamon 28 Aug 2008 at 4:47 pm

    Hi Albert,

    We haven’t seen that effect but you can check for the form type with this code:

    If (crmForm.FormType != 1) {
    HISTORY FRAME CODE HERE
    }

    This way the code will not fire if the user is creating a new record.

  19. JOhanon 11 Sep 2008 at 8:33 am

    Hello,

    Is it also possible to ajust this script so if you open an account and click on the quotes, you do not default see the Concept but the Active Quotes?
    Or is there another solution for tis problem?

    Tnx,

    Johan

  20. craigon 14 Nov 2008 at 8:55 pm

    This works fine in the browser for us on version 3.0, and in most desktop clients. However, it does not work at all on our laptop clients — and we have many.

    Why would the default to “ALL” work fine everywhere but on the laptop?

Trackback URI | Comments RSS

Leave a Reply