RSS

Changing Filter Condition in Associated View

19 Nov
Activities Associated View

Activities Associated View

Introduction

At times, we have the requirement to change the Filter Condition in an Associated View.

Background

In my case, the requirement was to show all the Activities when “Activities” Associated View is selected. The default Filter Condition in Activity Associated View is “Next 30 days“. I had to change it to “All“.

Code

Here is the code snippet to work this out. This function must be called on Load of the Form.

function filterAllActivities()
{
    //Calling function when activity is clicked
    document.getElementById("navActivities").onclick = function () {
        Mscrm.Details.loadArea(this, "areaActivities"); //loadArea is the predefined function

        //On load of the activity iframe change the filter
        document.getElementById("areaActivitiesFrame").onload = function () {
            var entityName = Xrm.Page.data.entity.getEntityName();
            var entity = entityName.charAt(0).toUpperCase() + entityName.substr(1);

            var doc = this.contentWindow.document; //Getting the document of the window

            //Getting the control of the 'Filter on' dropdown
            var filterOn = doc.getElementById("crmGrid_" + entity + "_ActivityPointers_datefilter");
            filterOn.value = "All"; //Changing the filter condition

            var evt = document.createEvent("HTMLEvents");
            evt.initEvent("change", false, true);
            filterOn.dispatchEvent(evt); //Dispatch event
        };
    };
}

By Ranjan Parhi
Senior Software Engineer @Team DynamicsCRM.
Mindfire Solutions

Advertisements
 
3 Comments

Posted by on November 19, 2013 in WebResources

 

Tags: , , , , , , , , , , , , , , ,

3 responses to “Changing Filter Condition in Associated View

  1. Ben Sim

    January 14, 2014 at 1:47 pm

    This is the first code I found that actually worked. Had to modify it a bit for it to work with Cases on Contacts, but thanks for the start!

     
    • DynamicsCRM@MindfireSolutions

      January 15, 2014 at 4:05 am

      Hi Ben Sim,

      Thanks for reading our Blog. 🙂 Glad to hear that it helped you.
      Please go through our other Blogs and be updated.

      Regards,
      DynamicsCRM@MindfireSolutions

       
    • Marty

      September 9, 2014 at 5:22 pm

      Ben – Could you share how you modified the script for Cases? Thanks!

       

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: