Model Driven App: disable “Open in Excel Online” button

🤔 The issue

The out-of-the-box Excel integration in Model Driven apps is a powerful, but very dangerous, feature.

Import from Excel, especially, can be very harmful because an user could leverage it to bypass any client side logic put on forms, generating inconsistent data within the system. Moreover, it cannot be customized: you cannot say “you can import opportunities records, but you cannot import accounts”, neither you could say “import works only on columns A, B, C”.

That’s the reason why, in most of the CRM (and MDAs) implementations I’ve seen so far, the Import from Excel button is disabled for standard users, and replaced with custom data-import capabilities.

Disabling the Import from Excel button is quite easy, It just requires from you to remove the Data Import and Data Map privileges from the role assigned to users.

Data Import and Data Map privileges removed from roles

It works… more or less…

…even if the Data Import privilege is removed, you can have the possibility to open the “Export In Excel” > “Open in Excel Online” capability

Open in Excel Online

With the edit capability enabled, and the Save button visible and clickable:

Save button

If you change something and click on Save, the following (ugly) error message appears (depending on the UI language of the user, mine is Italian)

Error message

That’s a behavior that looks more like a bug than a feature, IMHO.

The best would be to disable that “Open in Excel Online” button too… tipically for specific users/roles. But there is no such option in the role privileges…

😖 Failed fix tentatives

If you try to hide the button using Ribbon Workbench or the Modern Ribbon editor, you will quickly see that’s any customization on that button is disabled.

Disabled

👍🏻 How to do it

For people like me, mold by CRM implementations before Ribbon Workbench, the fix is quite straightforward: let’s tweak the RibbonDiffXml “the old way”.

First of all, let’s create a solution containing only the definition of the entity we want to disable that button for.

Temp solution

Temp solution

Then let’s use Power Platform CLI commands to export and unpack the solution in a local folder

pac solution clone --name temp

It generates locally a structure similar to the following:

Exported solution

Let’s open the RibbonDiff.xml file, it will be like the following one:


 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   />
  
     Id="Mscrm.Templates">
  
   />
  
     />
     />
     />
  
   />

In the node, let’s add a rule that is evaluated to “true” only in the case an user is system administrator (here you can use your fantasy)…


   Id="greg.tablename.IsSystemAdmin.DisplayRule">
     PrivilegeType="Delete" PrivilegeDepth="Basic" EntityName="solution" Default="false" InvertResult="false" />
  

Then, in the node, let’s add the following


   Id="Mscrm.ExportToExcel.Online">
    
       Id="Mscrm.ExportToExcel.ValidForXlsxExport" />
       Id="Mscrm.EnableExportToExcelOnlineForModern" />
       Id="Mscrm.EnableOnlyInBrowsersForModern" />
    
    
       Id="Mscrm.Live" />
       Id="Mscrm.IsExportToExcelFCBEnabled" />
       Id="Mscrm.HideOnOutlookClient" />
       Id="Mscrm.NotAdvancedFind" />
       Id="Mscrm.HideOnPhoneForNonModern" />
       Id="Mscrm.HideForTabletExperience" />
       Id="greg.tablename.IsSystemAdmin.DisplayRule" />
    
    
       FunctionName="XrmCore.Commands.Export.exportToExcel" Library="$webresource:Main_system_library.js">
         Value="SelectedControl" />
         Value="SelectedEntityTypeName" />
         Value="6" />
      
    
  

The final RibbonDiffXML should look something similar to the following:


 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   />
  
     Id="Mscrm.Templates">
  
  
     Id="Mscrm.ExportToExcel.Online">
      
         Id="Mscrm.ExportToExcel.ValidForXlsxExport" />
         Id="Mscrm.EnableExportToExcelOnlineForModern" />
         Id="Mscrm.EnableOnlyInBrowsersForModern" />
      
      
         Id="Mscrm.Live" />
         Id="Mscrm.IsExportToExcelFCBEnabled" />
         Id="Mscrm.HideOnOutlookClient" />
         Id="Mscrm.NotAdvancedFind" />
         Id="Mscrm.HideOnPhoneForNonModern" />
         Id="Mscrm.HideForTabletExperience" />
         Id="greg.tablename.IsSystemAdmin.DisplayRule" />
      
      
         FunctionName="XrmCore.Commands.Export.exportToExcel" Library="$webresource:Main_system_library.js">
           Value="SelectedControl" />
           Value="SelectedEntityTypeName" />
           Value="6" />
        
      
    
  
  
     />
    
       Id="greg.tablename.IsSystemAdmin.DisplayRule">
         PrivilegeType="Delete" PrivilegeDepth="Basic" EntityName="solution" Default="false" InvertResult="false" />
      
    
     />
  
   />

Now build the solution ad upload the generated solution zip file:

dotnet build
pac solution import --path .bindebugtemp.zip

Wait for the import to complete, then go to your environment, select the solution you just uploaded, and click Publish All Customizations.

Publish all

That’s it… Now that button will be visible only by System Administrator.

Hope this helps you too!

Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post

Angstrom Scientific Partners with ConnectomX to Distribute Katana in-situ SEM microtome in US

Related Posts