Guru Group LLC - Cloud Consulting & IT Solutions Provider | Microsoft & Salesforce Partner
  • Expertise
    • Microsoft Dynamics 365
      • Finance and Operations
      • Customer Relationship Management
      • Customer Engagement
      • Business Central
      • Dynamics 365 Security Services
    • Microsoft Fabric
      • How to build data cortex
    • Cloud Solutions
      • Microsoft Azure
      • DevOps
    • Microsoft Power Platform
    • Security Services
      • Application Security
      • Cloud Security
      • Network Security
      • Red Team Assessment
    • Revenue Cycle Management
    • Salesforce
    • SAP
    • Application Development
  • Products
      Guru Group LLC - Cloud Consulting & IT Solutions Provider | Microsoft & Salesforce Partner
    • Microsoft D365FO Connector for ADP Workforce Now
    • Guru Group LLC - Cloud Consulting & IT Solutions Provider | Microsoft & Salesforce Partner
    • BarTender Connector for D365
    • Guru Group LLC - Cloud Consulting & IT Solutions Provider | Microsoft & Salesforce Partner
    • ShipGuru
    • Guru Group LLC - Cloud Consulting & IT Solutions Provider | Microsoft & Salesforce Partner
    • BBPTechnologies
    • Guru Group LLC - Cloud Consulting & IT Solutions Provider | Microsoft & Salesforce Partner
    • LIS365
    • Guru Group LLC - Cloud Consulting & IT Solutions Provider | Microsoft & Salesforce Partner
    • HSBC Connector for Microsoft D365FO
    • Guru Group LLC - Cloud Consulting & IT Solutions Provider | Microsoft & Salesforce Partner
    • Paycrypt365 Connector for Microsoft D365FO
  • Industries
      Guru Group LLC - Cloud Consulting & IT Solutions Provider | Microsoft & Salesforce Partner
    • Healthcare
    • Guru Group LLC - Cloud Consulting & IT Solutions Provider | Microsoft & Salesforce Partner
    • Government
    • Guru Group LLC - Cloud Consulting & IT Solutions Provider | Microsoft & Salesforce Partner
    • Insurance
    • Guru Group LLC - Cloud Consulting & IT Solutions Provider | Microsoft & Salesforce Partner
    • Banking & Financial Services
    • Guru Group LLC - Cloud Consulting & IT Solutions Provider | Microsoft & Salesforce Partner
    • Manufacturing
    • Guru Group LLC - Cloud Consulting & IT Solutions Provider | Microsoft & Salesforce Partner
    • Retail & E-Commerce
  • Company
    • About Us
    • Case Studies
    • Blogs
    • Careers
  • Contact Us
  • Staffing Solutions

Add “Open in Excel” feature to a new custom form D365FO

Aamir Khan

15July

In Dynamics 365 Finance and Operation, Microsoft provides an Open in Excel feature to all the forms where details masters and simple list patterns are applied. It is an out-of-the-box functionality that checks If any data entity exists which have the same root data source as the current form.

Reference: In the All Customers form, the root data source is Custtable and CustCustomerV2Entity also has the same root data source, So the Open in Excel feature exists on this form which opens the data in Excel where you can modify, delete or add new data using Excel Add-in.

You can also add/remove options in this dialog by setting the visibility and creating more data entities having the same root data source as the form

Problem Statement:

Need to add a custom menu option that exports filtered records that are selected

Resolution:

You need to perform the following steps,

  • Implement the OfficeIGeneratedWorkbookCustomExporter interface.
  • Write your code in the getDataEntityContext(OfficeGeneratedExportMenuItem _menuItem) method
  • Get the ExportToExcelDataEntityContext object for your entity
  • Use its filter method to apply your filter


public class OpenSalesOrderForm extends FormRun implements OfficeIGeneratedWorkbookCustomExporter
{
    OfficeGeneratedExportMenuItem   filteredEntityMenuItem;
	
    public void customizeMenuOptions(OfficeMenuOptions _menuOptions)
    {
        filteredEntityMenuItem = OfficeGeneratedExportMenuItem::construct(tableStr(FilteredSOEntity), 'FilteredSOTable');
        filteredSOEntityMenuItem.displayName(strFmt('Filtered SO Table (%1)', curExt()));

        var dataEntityEnumerator = _menuOptions.dataEntityOptions().getEnumerator();

        while (dataEntityEnumerator.moveNext())
        {
            OfficeMenuDataEntityOptions dataEntityOptions = dataEntityEnumerator.current();

            if (dataEntityOptions.dataEntityName() == tableStr(FilteredSOEntity) )
            {
                dataEntityOptions.includeDefault(false);
            }
        }

        _menuOptions.customMenuItems().addEnd(filteredEntityMenuItem);
		
        filteredEntityMenuItem.visible(true);
    }

	ExportToExcelDataEntityContext getDataEntityContext(OfficeGeneratedExportMenuItem _menuItem)
    {
		SalesTable salesTableLocal = salesTable_ds.cursor();
        
		ExportToExcelDataEntityContext context = ExportToExcelDataEntityContext::constructDefault(literalStr(FilteredSOEntity));


		ExportToExcelFilterTreeBuilder filterBuilder = new ExportToExcelFilterTreeBuilder(_menuItem.dataEntityName());

		ListEnumerator entities = context.entities().getEnumerator();
		while (entities.moveNext())
		{
			if (entities.current().entityName() == _menuItem.dataEntityName())
			{
				entities.current().filter(filterBuilder.and(filterBuilder.companyFilter(),
				filterBuilder.areEqual(fieldStr(FilteredSOEntity, SalesId), salesTableLocal.SalesId)));
				break;
			}
		}
        return context;
    }
}
                                

Build Solution:

After building/re-building your solution in Visual Studio, you will be able to see the custom option in Open-In Excel and the out of the box option will be unavailable.

After clicking this option, you will be asked to download the Excel, and after opening the downloaded excel you will only see the filtered records in the Excel Sheet.

Tags:
D365 Dynamics 365 Office365 Microsoft AX Excel add-in Open in Excel Office Integration
Guru Group LLC - Cloud Consulting & IT Solutions Provider | Microsoft & Salesforce Partner

GuruGroup recognizes the importance of staying up to date through frequent self-inventions. We achieve this by continually attracting the brightest minds in modern digital paradigms and platforms.

  • About Us
  • Products
  • Industries
  • Blogs
  • Contact Us
  • Careers
  • Support
Guru Group LLC - Cloud Consulting & IT Solutions Provider | Microsoft & Salesforce Partner

104 S Woodburn Dr,
Dothan, AL 36305

Guru Group LLC - Cloud Consulting & IT Solutions Provider | Microsoft & Salesforce Partner

Phone: +1 334 446-5235

Guru Group LLC - Cloud Consulting & IT Solutions Provider | Microsoft & Salesforce Partner

Email: info@gurug.com

  • Guru Group LLC - Cloud Consulting & IT Solutions Provider | Microsoft & Salesforce Partner
  • Guru Group LLC - Cloud Consulting & IT Solutions Provider | Microsoft & Salesforce Partner
  • Guru Group LLC - Cloud Consulting & IT Solutions Provider | Microsoft & Salesforce Partner Guru Group LLC - Cloud Consulting & IT Solutions Provider | Microsoft & Salesforce Partner Guru Group LLC - Cloud Consulting & IT Solutions Provider | Microsoft & Salesforce Partner
| GuruGroup
  • Terms & Conditions
  • Privacy Policy
  • AI Usage Policy
Ask Guru Group
Hi! 👋 How may I help you today?