Showing posts with label insertEntityDataSource. Show all posts
Showing posts with label insertEntityDataSource. Show all posts

Monday, January 4, 2021

Method to extend standard data entity to map data source field when importing data into Dynamics 365 finance and operations

Scenario:- We need to update Bank statement entity data source field based on input value when we are importing the data into Dynamics 365 finance and operations.

Resolution: -

We need to write chain of commands/event handler for insertEntityDataSource entity method to achieve the same and logic should be written in pre event handler/ before next keyword.

Please find below sample code for your reference. 

[ExtensionOf(dataentityviewstr(BankStatementEntity))]
final class BankStatementEntity_Extension
{
    public boolean insertEntityDataSource(DataEntityRuntimeContext _entityCtx, DataEntityDataSourceRuntimeContext _dataSourceCtx)
    {
        BankStmtISOAccountStatement bankStatement;
        boolean ret;
        
        if (_dataSourceCtx.name() == dataentitydatasourcestr(BankStatementEntity, BankStmtISOAccountStatement))
        {
            if (this.ToDateTime == utcDateTimeNull())
            {
                throw error("To date must be specified");
            }
            bankStatement = _dataSourceCtx.getBuffer() as BankStmtISOAccountStatement;
            bankStatement.AccountingDate = DateTimeUtil::date(this.ToDateTime);  
            _dataSourceCtx.setBuffer(bankStatement);
        }

        ret = next insertEntityDataSource( _entityCtx,  _dataSourceCtx);
     
        return ret;
   
    }

}

Hope you find this helpful and will come up with another interesting blog, till then happy daxing....