将此功能添加到 javascript Web 资源

var _activitiesGridName = '';
function SetupActivityGridOnload(gridName)
{
    var btnsToHide =
    [
        'AddserviceappointmentButton',
        'AddcampaignresponseButton',
        'AddappointmentButton'
    ];
    _activitiesGridName = gridName;
    setTimeout(function ()
    {   //setting timeout beacuse subgid take some time to load after the form is loaded
        if (Xrm.Page != null && Xrm.Page != undefined)
        {   //validating to check if the sub grid is present on the form
            var grid = Xrm.Page.getControl(_activitiesGridName);
            if (!grid)
            {   // grid not loaded yet - call function again to recheck after timeout
                console.log('grid not loaded yet');
                SetupActivityGridOnload(_activitiesGridName);
            }
            else
            {   // grid loaded now hide unwanted activity buttons
                var menuItem = null;
                var parentMenu = null;
                $.each(btnsToHide, function (i, val)
                {
                    menuItem = document.getElementByIdval);
                    if (menuItem)
                    {
                        if (parentMenu == null)
                        {   // load parent node - if not already loaded
                            parentMenu = menuItem.parentNode;
                        }
                        console.log('removing menu item: ' + val);
                        parentMenu.removeChild(menuItem);
                    }
                    else
                    {
                        console.log('menu not found: ' + val);
                    }
                });
            }
        }
    }, 2000);
}

然后从 onload 事件调用该函数,将网格名称添加为参数,如此

StackOverflow 文档