Custom excel add in data entity on office menu in d365fo
Form should implemetns the following class
// Please check Custtable Form logic and for more complexity with template need to check
LedgerJournalTransCustPaym form logic
[Form]
public class EMSChargebackBreakupDetails extends FormRun implements OfficeIGeneratedWorkbookCustomExporter
{
const str breakupLinesEntityOfficeId = 'BreakupLinesUnFilteredId';
const str breakupLinesFilteredEntityOfficeMenuId = 'BreakupLinesFilteredId';
OfficeGeneratedExportMenuItem filteredBreakupLinesEntityMenuItem;
OfficeGeneratedExportMenuItem unFilteredBreakupLinesMenuItem;
public void customizeMenuOptions(OfficeMenuOptions _menuOptions)
{
/* var dataEntityEnumerator = _menuOptions.dataEntityOptions().getEnumerator();
while (dataEntityEnumerator.moveNext())
{
OfficeMenuDataEntityOptions dataEntityOptions = dataEntityEnumerator.current();
if (dataEntityOptions.dataEntityName() == tableStr(CustCustomerV3Entity) ||
dataEntityOptions.dataEntityName() == tableStr(CustDirectDebitMandateEntity))
{
dataEntityOptions.includeDefault(false);
}
}*/
element.initializeEntityMenuItems();
_menuOptions.customMenuItems().addEnd(unFilteredBreakupLinesMenuItem);
_menuOptions.customMenuItems().addEnd(filteredBreakupLinesEntityMenuItem);
element.enableOpenInOfficeMenuItems();
}
ExportToExcelDataEntityContext getDataEntityContext(OfficeGeneratedExportMenuItem _menuItem)
{
ExportToExcelDataEntityContext context = ExportToExcelDataEntityContext::constructDefault(_menuItem.dataEntityName());
if (_menuItem.id() == breakupLinesFilteredEntityOfficeMenuId)
{
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(EMSChargebackBreakupLineDetailsEntity,CBNum), SAKChargebacksInquiryView.CBNum)));
break;
}
}
}
return context;
}
private void initializeEntityMenuItems()
{
unFilteredBreakupLinesMenuItem = OfficeGeneratedExportMenuItem::construct(tableStr(EMSChargebackBreakupLineDetailsEntity), breakupLinesEntityOfficeId);
unFilteredBreakupLinesMenuItem.displayName(strFmt("breakupLine - All(%1)", curExt()));
filteredBreakupLinesEntityMenuItem = OfficeGeneratedExportMenuItem::construct(tableStr(EMSChargebackBreakupLineDetailsEntity), breakupLinesFilteredEntityOfficeMenuId);
filteredBreakupLinesEntityMenuItem.displayName(strFmt("breakupLine - Current(%1)", curExt()));
}
public void enableOpenInOfficeMenuItems()
{
/*var isDetailsPageActive = TabPageDetails.isActivePage();
if (filteredCustCustomerEntityMenuItem)
{
filteredCustCustomerEntityMenuItem.visible(isDetailsPageActive);
}
if (directDebitMandateMenuItem)
{
directDebitMandateMenuItem.visible(isDetailsPageActive);
}
if (unFilteredCustCustomerEntityMenuItem)
{
unFilteredCustCustomerEntityMenuItem.visible(!isDetailsPageActive);
}*/
}
For stanard form with event handlers
public static class EMSChargebackBreakupDetailsForm_Extension
{
/* const str formMenuItem = 'EMSChargebackBreakupDetails';
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[FormEventHandler(formStr(EMSChargebackBreakupDetails), FormEventType::Initialized)]
public static void EMSChargebackBreakupDetails_OnInitialized(xFormRun sender, FormEventArgs e)
{
FormRun formRun = sender as FormRun;
if (formRun)
{
OfficeFormRunHelper officeHelper = formRun.officeHelper();
if (officeHelper)
{
officeHelper.OfficeMenuInitializing += eventhandler(EMSChargebackBreakupDetailsForm_Extension::officeMenuInitializingHandler);
}
}
}
private static void officeMenuInitializingHandler(FormRun _formRun, OfficeMenuEventArgs _eventArgs)
{
OfficeGeneratedExportMenuItem emslinesEntityForm =
OfficeGeneratedExportMenuItem::construct(tableStr(EMSChargebackBreakupLineDetailsEntity),
formMenuItem);
emslinesEntityForm.displayName('breakup lines');
emslinesEntityForm.getDataEntityContext += eventhandler(EMSChargebackBreakupDetailsForm_Extension::getDataEntityContextHandler);
List customMenuItems = _eventArgs.menuOptions().customMenuItems();
customMenuItems.addEnd(emslinesEntityForm);
}
private static void getDataEntityContextHandler(OfficeGeneratedExportMenuItem _menuItem, FormRun _formRun, ExportToExcelDataEntityContext _dataEntityContext)
{
if (_menuItem.id() == formMenuItem)
{
_dataEntityContext.addEntityDefault(tablestr(EMSChargebackBreakupLineDetailsEntity));
}
} */
}
Comments
Post a Comment