There are times when hierarchy matters, when one object rolls up into another, and you need something like the subject lookup. Unfortunately the subject lookup is not an option you can turn on for your own lookups. However, thanks to some JScript from Tanguy you can override the default lookup control, making it launch your own web-interface. Yes, I know this is not supported, but at least the rest of this add-on follows the SDK guidelines.
UR12 / Polaris: the solution above does not work properly with UR12. I have not tested this UR12 solution with previous versions of CRM 2011. It no-longer requires you to specify the Set in the Set name, i.e. Category is just Category, not CategorySet. It uses the XrmSvcToolkit by Daniel Cai instead of the XrmServiceToolkit. You can download an unmanaged solution here. The technique used by Tanguy nolonger works, so I had to access the underlying behavior of the form element. I wish I could tell you that it won’t ever break, but there is no telling, because it is an unsupported modification. If you would like to do something supported, you can put a button on the ribbon to launch the custom web-resource and load the resulting data into the field.
Here is what it looks like:
Now, I won’t go into the details of how the web-resource works (you can look at my code), but here is how you use it:
- You can install either the unmanged or managed solution into your CRM
- Add the msblg_treelookup.js to your form scripts.
- In the form designer for your entity click on the Form Properties button.
- Click add, and search for name msblg_treelookup.js, select it, and click ok.
- Then add an event handler for the Form OnLoad (by scrolling down and clicking add)
- The parameters are:
- Attribute Name
- Entity Set Name (for the UR12 release, do not use Set, just use the entity name)
- Object Type Code
- The Id Field
- The Name Field
- The Parent Field (Lookup to the same entity)
- Title for the lookup window
- Description for the lookup window
- Column Header
- A REST filter that will be applied to all queries (not required)
- The parameters are:
The LookupTree function makes the existing lookup button launch the custom tree-view lookup. If you wanted to use this control in a completely supported manner, with some modifications you could add a button to launch the control.