Thursday, March 21, 2024

How to add custom fields in Open in Excel using standard entity

Using Resource :

Here my requirement is to add the custom field to Expense journal and export the data using Open in excel with custom template using standard entity.

Project management and accounting>Journals>Expense





Copy the name and search it in Document templates to download the existing template and to add our custom fields.

Organization administration > Office intigration > Document templates.

Reload the templates:


Download the existing template and add the field.

First add the field in Entity level.


After build, open the downloaded excel and add the field in excel.

click on design and select the entity in which custom fields are added.


select the field and click on update. Then field will be added in excel.


Create a Resource and add the updated excel file.





Create a class to get attach the custom template to form :

using Microsoft.Dynamics.Platform.Integration.Office;

   class DaxExpenseJournalClass extends DocuTemplateRegistrationBase implements LedgerIJournalExcelTemplate

   {

       // resource that contains xlsx file.

       private const DocuTemplateName ExcelTemplateName = resourceStr(DaxExpenseJournal);

       // lines Data Entity

       private const EntityName LineEntityName = tableStr(ExpenseJournalLineEntity);

       private const FieldName LineEntityJournalNum = fieldStr(ExpenseJournalLineEntity, JournalBatchNumber);

       private const FieldName LineEntityDataAreaId = fieldStr(ExpenseJournalLineEntity, dataAreaId);

       private const FieldName HeaderEntityName = tableStr(ExpenseJournalHeaderEntity);

       private const FieldName HeaderEntityJournalNum = fieldStr(ExpenseJournalHeaderEntity, JournalBatchNumber);

       // header Data Entity.

       private const FieldName HeaderEntityDataAreaId = fieldStr(ExpenseJournalHeaderEntity, dataAreaId);

   public void registerTemplates()

       {

           this.addTemplate(OfficeAppApplicationType::Excel,

                           ExcelTemplateName,

                           ExcelTemplateName,

                           "Dax Expense Journal",

                           "Dax Expense Journal",

                           NoYes::No,

                           NoYes::No);

       }

   public boolean isJournalTypeSupported(LedgerJournalType _ledgerJournalType)

       {

           // only daily journals are supported in this template.

           return _ledgerJournalType == LedgerJournalType::Cost;

       }

   public DocuTemplateName documentTemplateName()

       {

           return ExcelTemplateName;

       }

   public Set supportedAccountTypes()

       {

           // Set with supported account types.

           Set accountSetTypes = new Set(Types::Integer);

       accountSetTypes.add(LedgerJournalACType::Project);

           accountSetTypes.add(LedgerJournalACType::Ledger);

           return accountSetTypes;

       }

   public Set supportedOffsetAccountTypes()

       {

           // Set with supported offset account types.

           Set offsetAccountTypeSet = new Set(Types::Integer);

       offsetAccountTypeSet.add(LedgerJournalACType::Ledger);

           return offsetAccountTypeSet;

       }

   public boolean validateJournalForTemplate(LedgerJournalTable _ledgerJournalTable)

       {

           return LedgerJournalExcelTemplate::validateJournalForTemplate(_ledgerJournalTable, this);

       }

   public EntityName headerEntityName()

       {

           return HeaderEntityName;

       }

   public EntityName lineEntityName()

       {

           return LineEntityName;

       }

   public FieldName headerJournalBatchNumberFieldName()

       {

           return HeaderEntityJournalNum;

       }

   public FieldName headerDataAreaFieldName()

       {

           return HeaderEntityDataAreaId;

       }

   public FieldName lineJournalBatchNumberFieldName()

       {

           return LineEntityJournalNum;

       }

   public FieldName lineDataAreaFieldName()

       {

           return LineEntityDataAreaId;

       }

   public FilterCollectionNode appendHeaderEntityFilters(FilterCollectionNode _headerFilter, ExportToExcelFilterTreeBuilder _headerFilterBuilder)

       {

           return _headerFilter;

       }

   /// <summary>

   /// Filter the vouchers which are having accounttype as Project and offset account as Ledger

   /// </summary>

   /// <param name = "_lineFilter"></param>

   /// <param name = "_lineFilterBuilder"></param>

   /// <returns></returns>

   public FilterCollectionNode appendLineEntityFilters(FilterCollectionNode _lineFilter, ExportToExcelFilterTreeBuilder _lineFilterBuilder)

       {

           // creates excel filter to show only lines that have Bank account type

           // and Ledger offset account type

           FilterCollectionNode lineFilter = _lineFilterBuilder.and(

           _lineFilterBuilder.areEqual(fieldStr(ExpenseJournalLineEntity, AccountType), LedgerJournalACType::Project),

           _lineFilterBuilder.areEqual(fieldStr(ExpenseJournalLineEntity, OffsetAccountType), LedgerJournalACType::Ledger));

 

           return _lineFilterBuilder.and(_lineFilter, lineFilter);

       }

   public void applyCustomTrimming(Excel.IWorkbookManager _templateManaer, Excel.WorkbookSettingsManager _settingsManager, LedgerJournalTable _ledgerJournalTable)

   {

   }

}

.....................

A custom template is added to form.


When i export using the newly added template the data is being updated to custom field also.














No comments:

Post a Comment