Hi,
I have created one unmapped string field i.e reportstoWorkerName in Data Entity and I want to initialize this field on run time based on the data.
On the DataSource I have HcmpositionHierarchy table through that I can access the Parentpositionrecid than positionid -> worker and than the workername through X++.
The real Problem I am unable to access the datasource to access the parentpositionrecid that is available in HcmPositionHierarchy table.
I have use the below method to access the datasource but its not giving me the ReportsToWorkerName.
public void mapEntityToDataSource(DataEntityRuntimeContext _entityCtx, DataEntityDataSourceRuntimeContext _dataSourceCtx)
{
super(_entityCtx, _dataSourceCtx);
if (_entityCtx.getDatabaseOperation() == DataEntityDatabaseOperation::Insert || _entityCtx.getDatabaseOperation() == DataEntityDatabaseOperation::Update)
{
if (_dataSourceCtx.name() == dataentitydatasourcestr(TCSHcmWorkerPositionEntity, HcmPositionHierarchy)
{
HcmPositionWorkerAssignment hcmPositionWorkerAssignment;
HcmPositionHierarchy hcmPositionHierarchy = _dataSourceCtx.getBuffer();
hcmPositionWorkerAssignment = hcmPositionWorkerAssignment::findByPosition(hcmPositionHierarchy.ParentPosition);
this.ReportsToWorkerName = HcmWorker::find(hcmPositionWorkerAssignment.Worker).name();
}
}
}
The second approach that I am using is I have drag dropped the Parentpositionrecid from the datasource to the DataEntity Fields area.
and now at the run time I am using that field value to find the ReportsToWorkerName on the postLoad() method which is working fine.
below is the code.
public void postLoad()
{
HcmPositionWorkerAssignment hcmPositionWorkerAssignment;
super();
if(this.ParentPosition != 0)
{
hcmPositionWorkerAssignment = hcmPositionWorkerAssignment::findByPosition(this.ParentPosition);
this.ReportsToWorkerName = HcmWorker::find(hcmPositionWorkerAssignment.Worker).name();
}
}
My Question is that is there any possibility that we can access the datasource field value in any method instead of dropping datasource field on the field node of the data entity.
*This post is locked for comments