Filter N-N Add existing Look Up Contact Custom View CRM 2015

I had a requirement to add contacts where the [Account Type] is “Lawyer” to entity “Case”.  I created a relationship N:N between contacts and cases.

Unfortunately the filter for N-N Add Existing button on a sub grid stopped working on from version CRM 2013. It does not work on CRM 2015 on Premises as well.

I stumbled upon the blog Filter N:N Add Existing Lookup Dynamics CRM 2013 how to resolve the issue using the CRM function LookupObjectsWithCallback.

I created a view in the contacts list named “Lawyers” and noted down the view ID. To find the view Id, open the CRM solution which has the entity, expand entities and “contact”, select the view “Lawyers”.  Click on Arrow down next to Actions and select “Copy a Link”.FindCustomViewId The URL is in the following format.

<[CRM server]/[Organisation]/tools/vieweditor/viewManager.aspx?appSolutionId=%7bFD140AAF-4DF4-11DD-BD17-0019B9312238%7d&id=%7b5F90BBF5-4409-E511-80CF-00155D580900%7d>

Decode the url encoded id parameter into a valid GUID.


I created a .js file on the file system and examined the different parameters the method “LookupObjectsWithCallback” accepts and reconstructed the method so as the pop up dialog

  1. Allows selection of contact(s) from  only  Lawyers view
  2. Hides the New Button
  3. Hides other contact views
  4. Allows search of  contacts from  only  Lawyers view

The method “LookupObjectsWithCallback” can accept up to 25 parameters which are optional and position of the relevant parameter needs to be determined to update behaviour of dialog to select contact.

//filters an add existing lookup view (N:N)
function addExistingFromSubGridCustom(gridTypeCode, gridControl, context) {
var viewId = "{5F90BBF5-4409-E511-80CF-00155D580900}";//Lawyers
var relName = gridControl.GetParameter("relName");
var roleOrd = gridControl.GetParameter("roleOrd");
lookupStyle, // "single" or "multi"
showNew, // "0" or "1"
//pops the lookup window with our view injected
var parent = GetParentObject(null, 0);
var parameters = [gridTypeCode, "", relName, roleOrd, parent];
var callbackRef = Mscrm.Utilities.createCallbackFunctionObject("locAssocObjAction", context, parameters, false);
//Hide New Button, display only one view to pick up records, keep showing search button
LookupObjectsWithCallback(callbackRef, null, "multi", gridTypeCode, null, null, "", "0", null, 0, null, null, null, viewId, null, null, null, null, null, null, null, null, viewId);
//filters the Contact N:N lookup view from Case to show only Lawyers!!
function filterAddExistingContact(gridTypeCode, gridControl, primaryEntity) {
if (primaryEntity != "case") {
Mscrm.GridRibbonActions.addExistingFromSubGridAssociated(gridTypeCode, gridControl); //default button click function
addExistingFromSubGridCustom(gridTypeCode, gridControl, this );

I uploaded the js file to the web resources of the CRM solution having the entities (including contact) and application ribbon . I downloaded RibbonWorkbench2013 version to update the  behaviour of “Add Existing” button on the Contact Entity Sub Grid.

  • Open the Ribbon Workbench and select the CRM solution(s) containing the .js file, application ribbon and entities. Ensure no one else is modifying the CRM solution as their changes will be  lost when the ribbon workbench updates the solution.
  • When the solution is loaded into RibbonWorkbench, select entity contact.
  • Take an unmanaged backup of the CRM solution in case roll back is required
  • Under the SubGrid section, there are two “Add Existing” buttons, one for N:N and one for 1:N. The N:N ( is the second one. Right-Click on the second “Add Exiting” button and click on “Customize Command”
  • Expand “Commands” in the “Solution Elements”.
  • Select command  ‘Mscrm.AddExistingRecordFromSubGridAssociated’. In the “Properties: Command Action”  , replace the current FunctionName with the new function from your web resource (in the example code above, it’s the second function: filterAddExistingContact), and change the Library to the web resource. The parameter ” PrimaryEntityTypeName” needs to be added to the list of Parameters.


  • Click on Publish from the solution and solution will be reimported with the changes.


Navigate to the case entity form having the contacts sub grid to check whether only lawyers are displayed with no “New” button. When contacts Add Existing button for N:N relationships is clicked, the custom function displays only the Lawyers view.

Note: Filtering the Add Existing view using the method LookupObjectsWithCallback is unspported. It might break in the next release.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s