Skip to main content

Notifications

Announcements

No record found.

Filter N to N (Many to Many) Subgrid Lookup for Existing Records in CRM Without Modifying the Ribbon Action

Introduction and Post References

Basically, in this post, I just want to show how to filter the N to N lookup in the subgrid in CRM Form, without even modifying the Global Subgrid Ribbon in CRM.

image

In my previous post: http://missdynamicscrm.blogspot.sg/2015/07/filter-nn-subgrid-in-crm-2013-using.html, I have explained about a way how to filter the N to N Subgrid Lookup, but that is needed to modify the ribbon action globally and you might need to set another condition to actually skip is you need to filter only on specific entity, but your grid will be appearing in many entities, such as:

You want to filter the Contact lookup in, if you modify the subgrid ribbon, in every contact subgrid, the filter will be applied and you might need extra code of criteria to actually limit the  execution.
Good thing about that if your entity only used for single entity and you don’t need to specify is that only for subgrid or associated view, then modifying the ribbon is a better solution. however, if you want to filter only subgrid in specific entity or form, you can actually using another way.

Like you can refer to my posts:


So, in this post, basically I try to combine the ways to become one solution, to filter the N to N lookup that only applicable once the user load the form using single javascript.  This is unsupported customization, but, remember, modifying the N to N view also needs unsupported customization, so yeah, to reach the requirement we have to go further for unsupported customization eventhough strongly I also not recommend.

The Code

So, I just try to combine the code becoming:

*For CRM 2013

function modifyRibbon(subgridName) {
try {
//to store the original function ones
var originalFunctionAddNewStandard = Mscrm.GridRibbonActions.addNewFromSubGridStandard;
var originalFunctionAddExistingStandard = Mscrm.GridRibbonActions.addExistingFromSubGridStandard;
var originalFunctionAssociated = Mscrm.GridRibbonActions.addExistingFromSubGridAssociated;
//add new standard subgrid
Mscrm.GridRibbonActions.addNewFromSubGridStandard = function (gridTypeCode, parentEntityTypeCode, parentEntityId, primaryControl, gridControl) {
if (gridControl != null) {
if (gridControl.get_id() != subgridName) {
originalFunctionAddNewStandard(gridTypeCode, parentEntityTypeCode, parentEntityId, primaryControl, gridControl);
}
else {
originalFunctionAddNewStandard(gridTypeCode, gridControl);
filterTrainerProfile(gridTypeCode, gridControl);
}
}
}

//add existing standard subgrid
Mscrm.GridRibbonActions.addExistingFromSubGridStandard = function (gridTypeCode, gridControl) {
if (gridControl != null) {
if (gridControl.get_id() != subgridName) {
originalFunctionAddExistingStandard(gridTypeCode, gridControl);
}
else {
originalFunctionAddExistingStandard(gridTypeCode, gridControl);
filterTrainerProfile(gridTypeCode, gridControl);
                }
}
}
//add associate subgrid (N:N)
Mscrm.GridRibbonActions.addExistingFromSubGridAssociated = function (gridTypeCode, gridControl) {
if (gridControl != null) {
if (gridControl.get_id() != subgridName) {
originalFunctionAssociated(gridTypeCode, gridControl);
}
else {
originalFunctionAssociated(gridTypeCode, gridControl);
filterTrainerProfile(gridTypeCode, gridControl);
}
}
}
}
catch (ex) {
alert(ex);
}
}

*For CRM 2015

function modifyRibbon(subgridName) {
try {
//to store the original function ones
var originalFunctionAddNewStandard = Mscrm.GridCommandActions.addNewFromSubGridStandard;
var originalFunctionAddExistingStandard = Mscrm.GridCommandActions.addExistingFromSubGridStandard;
var originalFunctionAssociated = Mscrm.GridCommandActions.addExistingFromSubGridAssociated;
//add new standard subgrid
Mscrm.GridRibbonActions.addNewFromSubGridStandard = function (gridTypeCode, parentEntityTypeCode, parentEntityId, primaryControl, gridControl) {
if (gridControl != null) {
if (gridControl.get_id() != subgridName) {
originalFunctionAddNewStandard(gridTypeCode, parentEntityTypeCode, parentEntityId, primaryControl, gridControl);
}
else {
originalFunctionAddNewStandard(gridTypeCode, gridControl);
filterTrainerProfile(gridTypeCode, gridControl);
}
}
}

//add existing standard subgrid
Mscrm.GridRibbonActions.addExistingFromSubGridStandard = function (gridTypeCode, gridControl) {
if (gridControl != null) {
if (gridControl.get_id() != subgridName) {
originalFunctionAddExistingStandard(gridTypeCode, gridControl);
}
else {
originalFunctionAddExistingStandard(gridTypeCode, gridControl);
filterTrainerProfile(gridTypeCode, gridControl);
                }
}
}
//add associate subgrid (N:N)
Mscrm.GridRibbonActions.addExistingFromSubGridAssociated = function (gridTypeCode, gridControl) {
if (gridControl != null) {
if (gridControl.get_id() != subgridName) {
originalFunctionAssociated(gridTypeCode, gridControl);
}
else {
originalFunctionAssociated(gridTypeCode, gridControl);
filterTrainerProfile(gridTypeCode, gridControl);
}
}
}
}
catch (ex) {
alert(ex);
}
}

* So the filterTrainerProfile(gridTypeCode, gridControl); is your custom function to filter the view, some as you filter and create new custom view that I also have example in my previous post:
http://missdynamicscrm.blogspot.sg/2015/07/filter-nn-subgrid-in-crm-2013-using.html.

Remember, to get the GUID of the list record to show, you can always using CRM Javascript or in CRM 2013 and above you can use smarter way that is to combine with Custom Action, since Custom Action can be called through Javascript.

http://missdynamicscrm.blogspot.sg/search?q=custom+action

Hope this helps! Jiayou!

Comments

*This post is locked for comments