Scenario:
Requirement is to have a custom field showing Customer Number and Name.
Solution:
In that case instead of creating regular field on the Data entity and we will create a virtual field and fill the data at runtime when records are importing
Below are the steps needs to perform:
1. Create extension of the base entity (Example SalesOrderHeaderEntity) or your custom entity
2. Open the entity in designer and expand the fields
3. Right click and add new field -> StringUnmappedField
4. Set the Name property of new field, in our case I put ‘CustomerNumberAndName’
5. Set the IsComputedField Property to No.
6. Leave the DataEntityViewMethod Empty
7.Use the virtual field to receive the information from outside(odata or excel) and parse the information
8. Use chain of command or pre-post event handler if its base entity or customise the method ‘mapEntityToDataSource’
‘example of mapEntityToDataSpurce’
9.
public void mapEntityToDataSource(DataEntityRuntimeContext entityCtx, DataEntityDataSourceRuntimeContext dataSourceCtx) { next mapEntityToDataSource(entityCtx,dataSourceCtx); //Check if desired data source context is available switch (_dataSourceCtx.name()) { case dataEntityDataSourceStr(SalesOrderHeaderV2Entity, SalesTable): { SalesTable salesTable = _dataSourceCtx.getBuffer(); this.CustomerNumberAndName = salesTable.InvoiceAccount + ' - ' salesTable.customerName(); } break; } }
10. You can get the value from odata also to use it for different purpose as per request