Modify the Delete (Dustbin icon) Button in the CRM Subgrid
Views (18)
Overview
Sometimes we need to modify the Delete button in the CRM Subgrid, example:1. For preventing users to perform the delete button (but you dont want to just disable it)
2. Call another function or call custom function that needs client site programming (We can do plugin onDelete or onAssociate, but in case you want to show it in the client site)
3. To do impersonation
The Code
function modifyRibbon() {
modifySubgridDeleteButtonEventHandler("subgrid_name_in_the_form", deleteSubgridRecord, true);
discountStructureControl();
}
function deleteSubgridRecord() {
alert("test");
}
function modifySubgridDeleteButtonEventHandler(subgridName, functionToCall, passGridControl) {
try {
//to store the original function ones
var originalFunctionDeleteRecordSubgrid = Mscrm.GridCommandActions.deleteRecords;
debugger;
//add new standard subgrid
Mscrm.GridCommandActions.deleteRecords = function (selectedControl, selectedControlSelectedItemReferences, selectedEntityTypeCode) {
//if (typeof (gridControl.get_id).toString().toLowerCase() == "undefined") {} //no need since I replaced by the previous line
if (selectedControl.get_id() != subgridName) {
originalFunctionDeleteRecordSubgrid(selectedControl, selectedControlSelectedItemReferences, selectedEntityTypeCode);
}
else {
if (passGridControl) {
functionToCall(selectedControl);
}
else {
functionToCall();
}
}
}
}
catch (e) {
}
}
Result
*After clicking the ‘Delete’ button
Note: This method is overwriting the CRM functions and it works for CRM 2013, for CRM 2015/2016, this function [Mscrm.GridCommandActions.deleteRecords] might have been changed, so need to find out the current function name based on your CRM Version. And again, it means it is unsupported

Thanks!
This was originally posted here.
*This post is locked for comments