RE: How can I show custom error message on export to excel
Hi Kiran,
There is no simple way to show a custom validation message here.
However, there are 2 ways to do validation on export (nothing straight forward):
- Override Export to Excel button and in your custom JS function do the validation.
- Register a plugin on Retrieve Multiple message and do your validation in Plugin. If validation fails, you can throw an exception with custom message, like:
throw new InvalidPluginExecutionException("Message here....");
Please note there is no Export to Excel message available to register a a plugin,you have to use RetrieveMultiple message instead. To distinguish, between and Export Retrieve Multiple, see following thread:
https://stackoverflow.com/questions/36471302/distinguish-page-load-and-export-to-excel-in-crm-2015
Let me add extract from above article:
- At page load, context depth is 1, while at export to excel, context depth is 2.
- At page load, ParentContext is null, while at export to excel, ParentContext is not null and contains the following parameters: "View", "FetchXml", "LayoutXml", "QueryApi", "QueryParameters".
- When export to excel, the message of ParentContext is clearly labeled as "ExportToExcel".
Disclaimer: I did not test this solution, furthermore, this solution worked in CRM 2015, not sure if it works on Dynamics 365 v9.x.
Finally, i would suggest to re-evaluate the requirement as it requires a lot of effort to just show a custom message.
Feel free to discuss.
Best,
Wahaj