Monday, 27 May 2013

Set Activities filter on contact's entity form to All on MS Dynamics CRM 2011

The default filter for the activities lookup view on the contact form is Next 30 days, which is something that I was asked to change, so this is what I did.

The SetView function was registered on the onload event of the contact form and a parameter of 'All' was passed to set the view

function SetView(Value)
{
   SetDefaultView = function (viewCombo, viewName, appGrid)
   {
      if (viewCombo.value != viewName)
      {
         viewCombo.value = viewName;
      }
   }
/*I don't think this is actually needed, too lazy to check */
   areaActivitiesFrame_OnReadyStateChange = function ()
   {
      if (this.readyState == "complete")
      {
         var frame = getiFrame("areaActivitiesFrame");
         var viewCombo = frame.contentWindow.document.getElementById("crmGrid_Contact_ActivityPointers_datefilter");
         var appGrid = frame.contentWindow.document.getElementById("AppGridFilterContainer");
         if (viewCombo.readyState == "complete")
         {
            SetDefaultView(viewCombo, defaultValue, appGrid);
         }
         else
         {
            viewCombo.onreadystatechange = function ()
            {
               if (this.readyState == "complete")
               {
                  SetDefaultView(this, defaultValue, appGrid);
               }
            }
         }
      }
   }

   if (document.getElementById(navActivities) != null)
   {
      document.getElementById(navActivities).onclick = function ()
      {
         loadArea(this,"areaActivities");
         var iframe =  getiFrame(areaActivitiesFrame);

         iframe.onreadystatechange = function ()
         {
            if (this.readyState == "complete")
            {
               var frame = getiFrame("areaActivitiesFrame");
               var viewCombo = frame.contentWindow.document.getElementById("crmGrid_Contact_ActivityPointers_datefilter");               
               var appGrid = frame.contentWindow.document.getElementById("AppGridFilterContainer");
               if (viewCombo.readyState == "complete")
               {
                  SetDefaultView(viewCombo, defaultValue, appGrid);
               }
               else
               {
                viewCombo.onreadystatechange = function ()
                {
                   if (this.readyState == "complete")
                   {
                      SetDefaultView(this, defaultValue, appGrid);
                   }
                }
               }

            }
         }
      }
   }
}

function getiFrame(iframeName)
{
 var frames=document.getElementsByTagName('iframe');

  for(var i =0 ; i < frames.length;i++)
  {
    if (frames[i].name == iframeName)
     {
      var theFrame = frames[i];
     }
  }
 return theFrame;
}

No comments:

Post a Comment