Hi Sukrut,
Thanks so much for your help. I added the following code and do the data import, but the data import failed with no specific error. The import would succeed if there is no event handling. The event handling is trying to populate the billing code rate and ledger dimension because the out of box entity doesn't do that. I tried to set break point in event handling method but it doesn't stop there when I attached the debugger to iisexpress.exe. Any suggestion on what I did wrong?
class FreeTextInvoiceEntityEventHandler
{
/// <summary>
///
/// </summary>
/// <param name="_sender"></param>
/// <param name="_eventArgs"></param>
[DataEventHandler(tableStr(FreeTextInvoiceEntity), DataEventType::MappedEntityToDataSource)]
public static void FreeTextInvoiceEntity_onMappedEntityToDataSource(Common _sender, DataEventArgs _eventArgs)
{
DataEntityContextEventArgs entityContextEventArgs = _eventArgs as DataEntityContextEventArgs;
DataEntityRuntimeContext entityCtx = entityContextEventArgs.parmEntityContext();
DataEntityDataSourceRuntimeContext dataSourceCtx = entityContextEventArgs.parmEntityDataSourceContext();
CustBillingCode custBillingCode;
CustBillingCodeVersion custBillingCodeVersion;
CustBillingCodeRate custBillingCodeRate;
CustBillingCodeLedgerAccount custBillingCodeLedgerAccount;
if (dataSourceCtx.name() == dataEntityDataSourceStr(FreeTextInvoiceEntity, CustInvoiceLine ))
{
CustInvoiceLine custInvoiceLine = dataSourceCtx.getBuffer();
if (custInvoiceLine.AmountCur == 0)
{
select RecId from custBillingCode
where custBillingCode.BillingCode == custInvoiceLine.BillingCode;
if (custBillingCode.RecId != 0)
{
select RecId, RateFieldSelector from custBillingCodeVersion
where custBillingCodeVersion.CustBillingCode == custBillingCode.RecId;
}
if (custBillingCodeVersion.RecId != 0)
{
select Amount from custBillingCodeRate
where custBillingCodeRate.CustBillingCodeVersion == custBillingCodeVersion.RecId;
select LedgerDimension from custBillingCodeLedgerAccount
where custBillingCodeLedgerAccount.CustBillingCodeVersion == CustBillingCodeVersion.RecId;
if (custBillingCodeRate.Amount != 0)
{
if (custBillingCodeVersion.RateFieldSelector == RateField::LineAmount)
{
custInvoiceLine.AmountCur = custBillingCodeRate.Amount;
custInvoiceLine.UnitPrice = custBillingCodeRate.Amount;
}
else
{
custInvoiceLine.UnitPrice = custBillingCodeRate.Amount;
custInvoiceLine.AmountCur = custInvoiceLine.UnitPrice * custInvoiceLine.Quantity;
}
}
if (custBillingCodeLedgerAccount.LedgerDimension != 0)
{
custInvoiceLine.LedgerDimension = custBillingCodeLedgerAccount.LedgerDimension;
}
}
}
}
}
}