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.

5 comments:

  1. .AddParam is in the Red Issue List. whats the alternate of this for ur 12. My line of code is as follow:
    LookupAddress.AddParam("parentType", window.dialogArguments.Xrm.Page.data.entity.attributes.get("po_billtoaccount").getValue()[0].type);

    ReplyDelete
  2. The code I blogged above works for UR12. I'm unfamiliar with its operation in previous versions.

    ReplyDelete
  3. @ Anonymous & Dave:
    Since .AddParam is a red group issue, you can also try:

    Element._behaviors[0].set_additionalParams("string param");

    I use document.getElementById("StringElementName"); to find the field.

    ReplyDelete
  4. Actually...since document is no longer supported either:
    var el = Sys.Application.findComponent('FieldToGet');
    if(el != null){
    el._element._behaviors[0].set_additionalParams("Param");
    }
    }

    I saw the AddParam function as well...do you think there's any difference between that and set_additionalParams?

    ReplyDelete
  5. Functionally, I don't think so. I use "AddParam" because I have identified Microsoft code that also uses it; therefore, I am more certain that it will not likely change.

    ReplyDelete

Unrelated comments to posts may be summarily disposed at the author's discretion.