This code describes how to generate an exception and write detail log error message while importing a Data Entity.
public void mapEntityToDataSource(DataEntityRuntimeContext _entityCtx, DataEntityDataSourceRuntimeContext _dataSourceCtx)
{
//Retrieve purchTable.MatchingAgreement RecId to retrieve Purchase agreement during "PurchTable.Inserting" method
str errorTxt;
switch (_dataSourceCtx.name())
{
case dataEntityDataSourceStr(PurchPurchaseOrderHeaderV2Entity, PurchTable):
PurchPurchaseOrderHeaderV2Entity purchPurchaseOrderHeaderV2Entity = _entityCtx.getEntityRecord();
PurchTable purchTable = _dataSourceCtx.getBuffer();
if (purchPurchaseOrderHeaderV2Entity.Al0PurchAgreementRef != '')
{
PurchAgreementHeader purchAgreementHeader = PurchAgreementHeader::findAgreementId(purchPurchaseOrderHeaderV2Entity.Al0PurchAgreementRef);
if(purchAgreementHeader)
{
if (purchAgreementHeader.VendAccount == purchPurchaseOrderHeaderV2Entity.OrderVendorAccountNumber)
{
purchTable.MatchingAgreement = purchAgreementHeader.RecId;
}
else
{
errorTxt = strFmt("@Al0AM:Al0_00247_EntityPurchOrderHeaderAddFld_02",purchPurchaseOrderHeaderV2Entity.Al0PurchAgreementRef, purchPurchaseOrderHeaderV2Entity.OrderVendorAccountNumber);
}
}
else
{
errorTxt = strFmt("@Al0AM:Al0_00247_EntityPurchOrderHeaderAddFld_01",purchPurchaseOrderHeaderV2Entity.Al0PurchAgreementRef);
}
}
if(purchTable.MatchingAgreement == 0)
{
throw Error(errorTxt); //This method generate an exception and write error message into Data Entity Message log
}
break;
}
next mapEntityToDataSource(_entityCtx, _dataSourceCtx);
//Al0_00247_EntityPurchOrderHeaderAddFld - END
}
