20) Customize Open in Excel Menu in D365F&O
We are cognizant that the open in office (open in excel ) menu brings the data entities based on the root data source of the form and data entities.
In case where we need to customize the list of the data entities shown in the open in office menu where root datasource is not same as the form we can achieve by the following code customization.
We have a custom form in which the open in excel shows only two listings based on the data
entities of the root datasource of the form.
The user needed to see the list of master records. There is no form or enquiry form where the users could see the list of master records. One option could be provide a data entity but many users don't have access to data management form. So one of the option would be to provide the option where users could see the records in open in excel option.
Currenctly the available options shows the which contains mapping of the master records but not master records.
We created a data entity for the master table called KrishSalesMasterDataEntity,
Next at the form intializing event we can write the below code
public static class KrishComponentSalesMasterListPage_Extension { const str CustomExportTHSSalesMasterToExcelOptionId = 'ThsSalesMasterCustom'; /// <summary> /// Add <c>OfficeMenuEventArgs</c> so we can customize and add menu item for time Trade hierarchy sales master form. /// </summary> /// <param name = "sender">The form sender object.</param> /// <param name = "e">The form event args.</param> [FormEventHandler(formStr(ComponentSalesMasterListPage), FormEventType::Initializing)] public static void ComponentSalesMasterListPage_OnInitializing(xFormRun sender, FormEventArgs e) { FormRun formRun = sender as FormRun; if (formRun) { OfficeFormRunHelper officeHelper = formRun.officeHelper(); if (officeHelper) { officeHelper.OfficeMenuInitializing += eventhandler(KrishComponentSalesMasterListPage_Extension::officeMenuInitializingHandler); } } } private static void officeMenuInitializingHandler(FormRun _formRun, OfficeMenuEventArgs _eventArgs) { OfficeGeneratedExportMenuItem salesMasterMenuItem = OfficeGeneratedExportMenuItem::construct(tableStr(KrishSalesMasterDataEntity), CustomExportTHSSalesMasterToExcelOptionId); salesMasterMenuItem.displayName('@Krish:KrishDataEntity_3'); salesMasterMenuItem.getDataEntityContext += eventhandler(KrishComponentSalesMasterListPage_Extension::getDataEntityContextHandler); List customMenuItems = _eventArgs.menuOptions().customMenuItems(); customMenuItems.addEnd(salesMasterMenuItem); } private static void getDataEntityContextHandler(OfficeGeneratedExportMenuItem _menuItem, FormRun _formRun, ExportToExcelDataEntityContext _dataEntityContext) { if (_menuItem.id() == CustomExportTHSSalesMasterToExcelOptionId) { _dataEntityContext.addEntityDefault(tablestr(KrishSalesMasterDataEntity)); } } }
After adding the above code we could see the new option available in Open in Excel for the same form.
Hi Krishnendu!
ReplyDeleteI'm following your blog it is showing me menu option in "Open in excel" area. but when I click on download button it is giving me error("No public fields are specified for export").
It would be really appreciate able if u can guide me.
Thanks in advance.