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 FilesMicrosoft Dynamics CRM ServerCRMWeb_static_controlsappgridfiltercontainer
(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

26 replies
  1. Ridhima
    Ridhima says:

    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. oriol
    oriol says:

    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

  3. Brian
    Brian says:

    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?

  4. Brian
    Brian says:

    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.

  5. mdodd
    mdodd says:

    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.

  6. nitin daware
    nitin daware says:

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

  7. nitin daware
    nitin daware says:

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

  8. Pell
    Pell says:

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

  9. Halldojo
    Halldojo says:

    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)

  10. JB
    JB says:

    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!

  11. Jeetu
    Jeetu says:

    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,

  12. Unitek CRM Team
    Unitek CRM Team says:

    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.

  13. Doug
    Doug says:

    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?

  14. Unitek CRM Team
    Unitek CRM Team says:

    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?

  15. Albert
    Albert says:

    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?

  16. Unitek CRM Team
    Unitek CRM Team says:

    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.

  17. JOhan
    JOhan says:

    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

  18. craig
    craig says:

    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?

  19. Jim
    Jim says:

    This works nice.

    When listing the CONTRACTS for an account, I can get it to show all contracts, not just the draft contracts. Why do they default to draft contracts anyway?

    I would love to change the “include:” filter to show “This record only” instead of “Related “Regarding” Records” is this possible?

    Thanks
    Jim

  20. Bidhan Chakraborty
    Bidhan Chakraborty says:

    Hi there,
    i have used the following two functions for hiding “Add existing Activity to this record” button from a CRM form. but it did not work at all. could some one tell how to hide an associated button in CRM roll out 4.0?

    HideAssociatedViewButtons(‘entityRelationshipName’, [‘Add exisitng Activity to this record’]);

    function HideAssociatedViewButtons(loadAreaId, buttonTitles)
    {
    var isNativeEntity = false;
    var navElement = document.getElementById(‘nav_’ + loadAreaId);
    if (navElement == null)
    {
    navElement = document.getElementById(‘nav’ + loadAreaId);
    isNativeEntity = true;
    }

    if (navElement != null)
    {
    navElement.onclick = function LoadAreaOverride()
    {
    // Call the original CRM method to launch the navigation link and create area iFrame
    if (isNativeEntity)
    {
    loadArea(‘area’ + loadAreaId, ‘x26roleOrdx3d2’);
    HideViewButtons(document.getElementById(‘area’ + loadAreaId + ‘Frame’), buttonTitles);
    }
    else
    {
    loadArea(loadAreaId);
    HideViewButtons(document.getElementById(loadAreaId + ‘Frame’), buttonTitles);
    }
    }
    }
    }

    function HideViewButtons(Iframe, buttonTitles)
    {
    if (Iframe != null )
    {
    Iframe.onreadystatechange = function HideTitledButtons()
    {
    if (Iframe.readyState == ‘complete’)
    {
    var iFrame = frames[window.event.srcElement.id];
    var liElements = iFrame.document.getElementsByTagName(‘li’);

    for (var j = 0; j < buttonTitles.length; j++)
    {
    for (var i = 0; i < liElements.length; i++)
    {
    if (liElements[i].getAttribute(‘title’) == buttonTitles[j])
    {
    liElements[i].style.display = ‘none’;
    break;
    }
    }
    }
    }
    }
    }
    }

    your early concern into this matter would be highly appreciated
    thanks in advance

  21. Shannon
    Shannon says:

    I am a 3.0 user. And first, thanks for the extremely useful code! We added the code, corrected the quotation marks and changed the areaOppsFrame to areaQuotesFrame to show all quotes instead of all opportunities. We are now getting an error when we use quick create for contacts. Has anyone else experienced that? Is there a fix?

    “There was an error with this field’s customized event.
    Field: crmForm
    Event: onload
    Error: ‘tdAreas’ is undefined”

  22. Klaus
    Klaus says:

    I have tried the trick of Stunnware: http://www.stunnware.com/crm2/topic.aspx?id=js33 with success, but I can’t find the trick to make it work for the Activities too.

    I tried to add this piece of modified code in the onload event of the Account form:

    areaActivitiesFrame_OnReadyStateChange = function() {

    /* Waiting until the frame has finished loading */
    if (this.readyState == “complete”) {

    /* This is the frame we’re interested in */
    var frame = document.frames(“areaActivitiesFrame”);

    /* And this is the view combo box */
    var viewCombo = frame.document.getElementById(“actualend”);

    /* This is the AppGridFilterContainer control we need to refresh the view */
    var appGrid = frame.document.getElementById(“AppGridFilterContainer”);

    /* The view combo box uses a style sheet that references a HTML
    * control. We have to wait until the htc file is loaded,
    * otherwise the call to FireOnChange in the SetDefaultView
    * method will fail. */
    if (viewCombo.readyState == “complete”) {

    /* If the control already has finished loading, we can
    * directly set the new view. */
    SetDefaultView(viewCombo, “All”, appGrid);
    }

    else {
    /* Otherwise we have to register another event handler
    * waiting until all of the include files used by the
    * combo box are loaded as well. */
    viewCombo.onreadystatechange = function() {
    if (this.readyState == “complete”) {
    SetDefaultView(this, “All”, appGrid);
    }
    }
    }
    }
    }

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

    But unfortunately it doesn’t work and it fails when closing the Account form.

    Do anybody have a working Onload script that works for both activities and history ?

  23. Rajeev
    Rajeev says:

    HideAssociatedViewButtons(’entityRelationshipName’, [‘Add exisitng Activity to this record’]);

    Hi,
    I tried using the above function to hide the ‘new Activity’ button in History in the left navigation pane but it doesn’t work, instead it hides the complete right pane.

    Kindly help in doing this task.

  24. Chris
    Chris says:

    I have tired this as well on 4.0, replace the quotations by typing them in manually and deleting the copied ones. This is still not working.

    Below is my code, if anyone wouldn’t mind telling me what I am doing wrong. Thanks in advanced. Am I looking at the wrong thing or thinking this does something else? When someone goes to Contact or Account History the default should change from 30Days to All. Thanks again

    var _oGrid = null;

    function Initialize()
    {

    _oGrid = ownerDocument.all[GridId];

    if(autorefresh == “1”)
    {
    IterateControls(SetEventHandler);
    }
    }

    function SetEventHandler(oCtrl)
    {
    oCtrl.attachEvent(“onchange”, RefreshGridView);
    }

    function RefreshGridView()
    {

    var sViewId = _oGrid.GetParameter(“viewid”);

    IterateControls(SetGridParameters);

    if (sViewId != _oGrid.GetParameter(“viewid”))
    {
    _oGrid.Reset();
    }
    else
    {
    _oGrid.Refresh();
    }
    }

    function SetGridParameters(oCtrl)
    {
    switch(oCtrl.className)
    {

    case “AppGridFilterSelector”:
    var oKeyValuePairs = oCtrl.DataValue;
    if(!IsNull(oKeyValuePairs))
    {
    for(var oKey in oKeyValuePairs)
    {
    _oGrid.SetParameter(oKey, oKeyValuePairs[oKey]);
    }
    }
    break;

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

    function IterateControls(oCallback)
    {

    var oCtrl = null;

    var iLen = element.all.length;

    for(var i = 0; i < iLen; i++)
    {

    oCtrl = element.all[i];

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

    i += oCtrl.all.length + 1;
    }
    }
    }

Trackbacks & Pingbacks

Comments are closed.