Pages

Wednesday, February 6, 2013

Add Parameters to CRM 2011 Lookup Dialog

Alternate Title: How to hide the “New” or “Properties” button from the CRM 2011 Lookup Dialog.

Following on the heels of yesterday’s post, I have finally discovered a way to eliminate the pesky “New” and “Properties” buttons from the Lookup dialog.  This was, again, easier accomplished in the previous version of CRM, with the following code:

   1:  crmForm.all.<lookup>.AddParam("ShowNewButton", 0);

As we’ve seen before, this function did not disappear from CRM 2011—it was simply moved.  Now, this function is invoked somewhat implicitly via a behavioral association to a highly organized JavaScript object structure.  Yet again, hours of pouring over Developer Tools in Internet Explorer (this time with a lot more Profiling and debugging), I have figured out how Microsoft does it.

Here’s the new way to hide the “New” button:

   1:  var lookupControl = Sys.Application.findComponent("some_lookupid");
   2:   
   3:  if (lookupControl != null)
   4:  {
   5:      lookupControl._element._behaviors[0].AddParam("ShowNewButton", 0);
   6:  }

Like most of the things on this blog, this is highly unsupported, but I personally believe that this is a harmless hack.  There is one caveat, however, to the above code:

  • The ‘_behaviors’ member is a collection of references to classes.  For every Lookup I could find, there was only one entry, and it exposed the “AddParam” function.  Conceivably, there could be other Lookups with multiple behaviors, and the first item in ‘_behaviors’ may not be the one you want.  You have been warned.