Composite data entity datasources insert
Examples:
InventInventoryAdjustmentJournalEntryV2Entity
InventInventoryAdjustmentJournalEntryCDSEntity
Align the datasources in following way
Primary datasource make it line one , So that system automatically inserts the line data and just before inserts the line data we insert the header data
public class MCOInventTransferOrdersEntity extends common
{
/// <summary>
///
/// </summary>
public void postLoad()
{
super();
this.ProductName = InventTable::find(this.ItemId).itemDescriptionOrName();
}
/// <summary>
/// Executes logic for optimizing staging data before copy to target.
/// </summary>
/// <param name="_dmfDefinitionGroupExecution">
/// The definition group that should be processed.
/// </param>
/// <param name="_approxNumberOfLines">
/// Approx number of lines included in the same inventory journal; optional.
/// </param>
/// <remarks>
/// The staging data will be updated with journal number and line number for the lines imported that only includes journal name id.
/// </remarks>
public static void postGetStagingData(DMFDefinitionGroupExecution _dmfDefinitionGroupExecution, int64 _approxNumberOfLines = 1000)
{
MCOInventTransferOrdersStaging stagingRecord;
InventTransferTable transferTable;
ttsbegin;
while select TransferId,InventLocationIdFrom,InventLocationIdTo,maxof(ShipDate),maxof(ReceiveDate), DlvMode
from stagingRecord group by TransferId,InventLocationIdFrom,InventLocationIdTo, DlvMode
where stagingRecord.DefinitionGroup == _dmfDefinitionGroupExecution.DefinitionGroup
&& stagingRecord.ExecutionId == _dmfDefinitionGroupExecution.ExecutionId
notexists join transferTable
where transferTable.TransferId == stagingRecord.TransferId
{
InventTransferTable transferTableInsert;
transferTableInsert.initValue();
transferTableInsert.TransferId = stagingRecord.TransferId;
transferTableInsert.InventLocationIdFrom = stagingRecord.InventLocationIdFrom;
transferTableInsert.InventLocationIdTo = stagingRecord.InventLocationIdTo;
transferTableInsert.initFromAddress();
transferTableInsert.initToAddress();
transferTableInsert.ShipDate = stagingRecord.ShipDate ;
transferTableInsert.ReceiveDate = stagingRecord.ReceiveDate ;
transferTableInsert.DlvModeId = stagingRecord.DlvMode ;
transferTableInsert.InventLocationIdTransit = InventLocation::find(transferTableInsert.InventLocationIdFrom).InventLocationIdTransit;
transferTableInsert.insert();
}
ttscommit;
}
public TableExtension getExtension()
{
return new SysTableExtension();
}
public boolean insertEntityDataSource(DataEntityRuntimeContext _entityCtx, DataEntityDataSourceRuntimeContext _dataSourceCtx)
{
InventDim inventDim ;
InventTransferLine transferline ;
switch (_dataSourceCtx.name())
{
case dataEntityDataSourceStr(MCOInventTransferOrdersEntity, InventDim):
// Read only data source was handled by mapEntityToDataSource(...)
return true;
case dataEntityDataSourceStr(MCOInventTransferOrdersEntity, InventTransferLine):
transferline = _dataSourceCtx.getBuffer();
inventDim.configId = this.configId;
inventDim.InventStyleId = this.InventStyleId;
inventDim.InventColorId = this.InventColorId;
inventDim.InventSizeId = this.InventSizeId;
inventDim.InventSiteId = this.InventSiteId;
inventDim.InventLocationId = this.InventLocationIdFrom;
inventDim.initFromInventLocation(inventDim.inventLocation());
inventDim = InventDim::findOrCreate(inventDim);
transferline.InventDimId = (inventDim.inventDimId);
transferline.initFromInventTable(InventTable::find(transferline.ItemId), transferline.InventDimId);
transferline.QtyTransfer = this.QtyTransfer ;
transferline.QtyRemainReceive = transferline.QtyTransfer;
transferline.QtyRemainShip = transferline.QtyTransfer;
break;
}
boolean ret = super(_entityCtx, _dataSourceCtx);
if (ret)
{
if (_dataSourceCtx.name() == dataEntityDataSourceStr(MCOInventTransferOrdersEntity, InventTransferLine))
{
// Need to re-apply inventory dimensions as defaulting logic may have changed them:
transferLine = _dataSourceCtx.getBuffer();
inventDim.configId = this.configId;
inventDim.InventStyleId = this.InventStyleId;
inventDim.InventColorId = this.InventColorId;
inventDim.InventSizeId = this.InventSizeId;
inventDim.InventLocationId = this.InventLocationIdFrom;
inventDim.initFromInventLocation(inventDim.inventLocation());
inventDim = InventDim::findOrCreate(inventDim);
transferline.InventDimId = (inventDim.inventDimId);
}
}
return ret;
}
public boolean updateEntityDataSource(DataEntityRuntimeContext _entityCtx, DataEntityDataSourceRuntimeContext _dataSourceCtx)
{
switch (_dataSourceCtx.name())
{
case dataEntityDataSourceStr(MCOInventTransferOrdersEntity, InventDim):
// Read only data source was handled by mapEntityToDataSource(...)
return true;
}
return super(_entityCtx, _dataSourceCtx);
}
public void mapEntityToDataSource(DataEntityRuntimeContext _entityCtx, DataEntityDataSourceRuntimeContext _dataSourceCtx)
{
this.skipDataSourceValidateField(fieldNum(MCOInventTransferOrdersEntity, LineNum), true);
super(_entityCtx, _dataSourceCtx);
switch (_dataSourceCtx.name())
{
case dataEntityDataSourceStr(MCOInventTransferOrdersEntity, InventDim):
switch (_entityCtx.getDatabaseOperation())
{
case DataEntityDatabaseOperation::Insert:
case DataEntityDatabaseOperation::Update:
InventDim inventDim = this.InventInventoryDimensionEntityFieldsMapping::resolveInventDim();
_dataSourceCtx.setBuffer(inventDim);
var journalTransContext = _entityCtx.getRuntimeContextByName(dataEntityDataSourceStr(MCOInventTransferOrdersEntity, InventTransferLine));
InventTransferLine transferline = journalTransContext.getBuffer();
//InventTransferTable table = InventTransferTable::find(transferline.transferid);
inventDim.InventLocationId = this.InventLocationIdFrom;
inventDim.initFromInventLocation(inventDim.inventLocation());
inventDim = InventDim::findOrCreate(inventDim);
transferline.InventDimId = (inventDim.inventDimId);
break;
}
break;
}
}
public void mapDataSourceToEntity(DataEntityRuntimeContext _entityCtx, DataEntityDataSourceRuntimeContext _dataSourceCtx)
{
if (_dataSourceCtx.name() == dataEntityDataSourceStr(MCOInventTransferOrdersEntity, InventTransferLine))
{
InventTransferLine transferline = _dataSourceCtx.getBuffer();
InventDim inventDim = transferline.inventDim();
this.InventSizeId = inventDim.InventSizeId;
this.InventColorId = inventDim.InventColorId;
this.configId = inventDim.configId;
this.InventStyleId = inventDim.InventStyleId;
}
super(_entityCtx, _dataSourceCtx);
}
}
Comments
Post a Comment