Tuesday, May 19, 2015

Hide / Show Export to Excel button for specific Entity / Specific View

In MS CRM, Export to excel feature is enabled or disabled from security role.
You can have this feature for all applicable entities or none of the entity.
But sometime we have requirement to hide export to excel from particular entity, or show only for particular entity.
With Security role this requirement is not possible, but will little JavaScript code and ribbon customization we can achieve this.

Case 1: Hide Export to Excel button from contact Home grid.

1.      Create one custom solution
2.      Add Application Ribbons – from client Extensions





3.      Create one JavaScript web resource in this solution and add following code

function ShowHideExport2Excel(SelectedEntityTypeName) {
    if (SelectedEntityTypeName == 'contact')
        return false// hide button
    else
        return true//show button
}

4.       Now Open this custom solution into Ribbon workbench
5.      In the Entities list you will see ApplicationRibbon
6.      Select Export to Excel button from Home, right click and Customize command



7.      In Commands, you will see Mscrm.ExportToExcel
8.      Now add custom Enable Rule to this command. Keep existing enable rules.
9.      When adding enable rule, add Custom JavaScript rule.
Default: True
FunctionName: ShowHideExport2Excel
invertResult: False
Library: your JavaScript library
Parameters :  [Crm Parameter] = SelectedEntityTypeName

10.  Add Crm Parameter to Custom JavaScript rule, value of this parameter must be SelectedEntityTypeName

11.   Save and publish your customization.
12.  Now Export to Excel button is hidden for Contact home grid.

Export To Excel button is not showing now.



 Export To Excel button is showing now.



Case 2: Show Export to Excel button only for contact Home grid.

In this case you just need to change JavaScript code little bit as

function ShowHideExport2Excel(SelectedEntityTypeName) {
    if (SelectedEntityTypeName == 'contact')
        return true// show button
    else
        return false//hide button
}


Case 3: Show Export to excel button for particular entity and particular view only

[To do this need to use Unsupported JavaScript code]
To do this, we need to add one more Crm parameter to enable rule, and select value to this parameter is SelectedControl



And modify JavaScript function as

For MS CRM 2013 :

function ShowHideExport2Excel(SelectedEntityTypeName, selectedCtrl) {
    if (SelectedEntityTypeName == 'contact') {
        var view = selectedCtrl.get_$1X_3();
        var viewName = view.selectedViewName;
        if (viewName == 'My Active Contacts') //Change "My Active Contacts" with Your view name to show Export To Excel button
            return true; // show button
        else
            return false; // hide button
    }
    else
        return true;
       
}

For MS CRM 2015:

function ShowHideExport2Excel(SelectedEntityTypeName, selectedCtrl) {
    if (SelectedEntityTypeName == 'contact') {        
        var viewName = selectedCtrl.get_viewTitle();
        if (viewName == 'My Active Contacts'//Change "My Active Contacts" with Your view name to show Export To Excel button
            return true// show button
        else
            return false// hide button
    }
    else
        return true;
       
}

2 comments:

  1. Hi,

    It's a very good article, I've one issue with my CRM 2016 where export to excel button got disabled for a specific entity on advanced find query. Please let me know how can I enable it??

    ReplyDelete
  2. THANK YOU FOR THE INFORMATION
    PLEASE VISIT US
    CRM Solutions



    ReplyDelete