Thursday, November 7, 2024

D365: When and how to use mapEntityToDatasource() method

/// <summary>
/// This method checks if there is an existing <c>VendInvoiceInfoSubTable</c> record, if not we create one
/// and initialize the DocumentOrigin field of the <c>VendInvoiceInfoTable</c> record.
/// </summary>
/// <param name = "_entityCtx"></param>
/// <param name = "_dataSourceCtx"></param>
public void mapEntityToDataSource(DataEntityRuntimeContext _entityCtx, DataEntityDataSourceRuntimeContext _dataSourceCtx)
{
    if (_entityCtx.getDatabaseOperation() == DataEntityDatabaseOperation::Insert)
    {
        switch (_dataSourceCtx.name())
        {
            case dataentitydatasourcestr(VendorInvoiceHeaderEntity, VendInvoiceInfoTable):
                VendInvoiceInfoTable vendInvoiceInfoTable = _dataSourceCtx.getBuffer();
                vendInvoiceInfoTable.DocumentOrigin = DocumentOrigin::Service;
                this.VendorInvoiceReviewStatus = VendInvoiceRequestStatus::Draft;
                break;
        }        
    }
 
    super(_entityCtx, _dataSourceCtx);
}