|
09.10.2024, 16:12 | #1 |
Участник
|
erconsult: Import a D365 FO entity with a virtual KEY field
Источник: https://erconsult.eu/blog/import-a-d...ual-key-field/
============== Import a D365 FO entity with a virtual KEY field
I’ve got a case recently where a delimited text file had to be imported into Dynamics where a key field was a virtual one. Namely, an external APS system sent a single ProdOprNum of the record, whereas the respective ProdRoute table in Dynamics 365 for SCM has a composite key ProdId + OprNum. Pre-processing the file with an XSLT and splitting the column was not an option, because the Microsoft XSLT parser still does not implement the XSLT 2.0 standard and cannot uptake a text file. The most important lesson to learn was that the – generally useful – guidance Use a virtual field to receive and parse an inbound field | Microsoft Learn did not work, because the system kernel started looking for the record to update BEFORE the compound key was parsed in the mapEntityToDataSource() method of the entity. It was not able to find the right record to update, which lead to an error later on. The solution is as follows:
public void initializeEntityDataSource(DataEntityRuntimeContext _entityCtx, DataEntityDataSourceRuntimeContext _dataSourceCtx) { super(_entityCtx, _dataSourceCtx); switch (_dataSourceCtx.name()) { case dataEntityDataSourceStr(ProdRouteSchedEntity, ProdRoute): ProdRoute prodRoute = _dataSourceCtx.getBuffer() as ProdRoute; if (! prodRoute) { this.ProdId = substr(this.ProdOprNum, 1, 10); this.OprNum = any2int(substr(this.ProdOprNum, 11, 14)); prodRoute = ProdRoute::find(this.ProdId, this.OprNum, RouteOprPriority::Primary, true); } _dataSourceCtx.setBuffer(prodRoute); } break; } }} X++ programming blog series Further reading: Print a custom product label: a Template solution in Process Guide Framework, with detours Extending SysOperation contracts with DataMemberAttribute X++ Decorator pattern in Dynamics 365 Get a cost center in D365FO Find and merge a DimensionAttributeValue SysExtension framework pitfall: avoid new() Input validation and messaging in the Process Guide Framework The post Import a D365 FO entity with a virtual KEY field appeared first on ER-Consult. Источник: https://erconsult.eu/blog/import-a-d...ual-key-field/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору. |
|