Tuesday, July 28, 2009

Microsoft CRM Multi Select Picklists, Many to Many Relationships and Advanced Find

I love using the many to many (n:n) relationship in Microsoft CRM 4.0. I most often use it to create a solution for a multi select picklist requirement. For example I may have a requirement to track which industries an account belongs to. The problem is an account can be linked to more than one industry – I need a multi select picklist. Now there are a multitude of solutions out there for multi select picklists, most are really elegant when it comes to the UI and usability but pose all sorts of problems when it comes to searching using Advanced Find. That’s where the n:n relationships can provide a great solution.

Continuing our example above I have created a new entity called industry and linked it to the account entity using an n:n relationship. The result is Industry now appears as a new menu item appears on the left hand navigation bar in the Account screen.

image

Many users however would rather have the Industry listing  on the form itself rather than as a menu item. To solve this I place the n:n related entity in an IFrame on the form using the great solution CRM 4.0 Many 2 Many IFrame Viewer by Adi Katz. The best thing about Adi’s solution is that the IFrame is automatically refreshed after updating your selections.

image

To make the solution a little cleaner I would like to remove the Industries menu item on the left hand navigation bar. Now you can achieve this by setting the Display Option in the n:n relationship settings to Do Not Display as shown below.

image

However this will remove the relationship in the Advanced Find and I can no longer search industries as a Related Entity to Accounts in the Advanced Find screen. Strangely enough this is only a problem with an n:n relationship.

image Industries will only appear as a Related entity in Advanced Find if the display option is set to “Use Plural Name” or “ Use Custom Label” If you use the latter the entity name will be what ever you used as your Custom Label.

To solve this problem rather than removing the menu item from the left hand nav bar by setting the Display Option to Do Not Display, you can remove it by using some simple JavaScript in the form onload event.

function ShowHideLeftNav(strNavItemID, blnVisible)
{
    try
    {
    var NavItem = document.all["crmNavBar"].all[vstrNavItemID];
    NavItem.style.display = (blnVisible == true) ? "inline" : "none";
    }
    catch (e)
    {
    }
}

ShowHideLeftNav('navnew_new_industry_account', false);

Typically the strNavItemID parameter is the name of the n:n relationship prefixed with nav. So in our example it is 'navnew_new_industry_account'. You can also use the IE developer toolbar (now built in to IE 8) to retrieve this.

Now you have a great solution for a multi select picklist on the form, have not confused users with multiple locations to update the list and have maintained the Advanced Find functionality :)

2 comments:

Su said...

Hi Karl,

This post is really very useful.

Thanks and Reagrds,
Asha Gogi

Vahag said...

Thanks much ))

Vahagn