top of page

Lets import Data in a minute

BeyondDataImporter for Microsoft Dynamics 365 Business Central provides an interface called "BYD DI IProcessor" which allows for streamlined and efficient data import into Business Central tables.

Wondering how fast an implementation could be?

Write an enumextension:

enumextension 60000 "PC PostCode" extends "BYD DI Processor"
    value(60000; PostCode)
        Caption = 'Post Code';
        Implementation = "BYD DI IProcessor" = "PC Post Code Processor";

And implement the following interface:

interface "BYD DI IProcessor"
    procedure GetTableNo(): Integer;
    procedure GetTemplateFields(var Rec: Record "BYD DI Template Field" temporary);
    procedure OnChunkLoaded(Rec: Record "BYD DI Template"; Chunk: JsonArray);
    procedure OnImportFinished(Rec: Record "BYD DI Template");

Here’s a breakdown of the key components and functionalities:

1. Interface Implementation:

  • "BYD DI IProcessor" indicates that this codeunit conforms to the "BYD DI IProcessor" interface, which requires specific methods to be implemented for processing data.

2. Procedures and Functions:

  • GetTableNo(): This function returns the ID of the "Post Code" table, specifying which table this processor will interact with.

  • GetTemplateFields(var Rec: Record "BYD DI Template Field" temporary): This method sets up the template fields necessary for the import process, indicating which fields are required, and whether relations need validation.

  • OnChunkLoaded(Rec: Record "BYD DI Template"; Chunk: JsonArray): This procedure is triggered when a chunk of data is loaded, starting the process to handle the data chunk.

  • ProcessChunk(Rec: Record "BYT DI Template"; Chunk: JsonArray): Processes each piece of the loaded JSON data array, mapping and inserting them into the temporary "Post Code" table.

  • OnImportFinished(Rec: Record "BYD DI Template"): Finalizes the import process, providing a summary of the records created and updated.

3. Data Processing:

  • The ProcessChunk method uses the RecordRef and FieldRef mechanisms to dynamically determine field types and assign values from the JSON array to corresponding fields in the "Post Code" table. This generic handling supports different field types like Integer, Decimal, Boolean, and Date, using appropriate formatting and type conversion.

  • Each JSON object is translated into field values, handling data according to the Business Central field data types and ensuring data integrity with ConfigValidateMgt.EvaluateTextToFieldRef.

4. Error Handling and Updates:

  • The import process checks if a record already exists using the primary key (in this case, "Code" and "City"). It either updates existing records or inserts new ones, tracking the count of these operations.

5. Performance Optimization:

  • The code unit makes use of temporary tables and record references to enhance performance, reducing the overhead of directly dealing with database tables. This approach is particularly beneficial in batch processing scenarios, like importing data.

And this is how it looks like:

Take our implementation code for free:

Overall, the codeunit is designed for efficiency and flexibility, allowing easy adaptation for importing different datasets by merely implementing the necessary interface and adjusting field mappings and processing logic.

43 Ansichten0 Kommentare

Aktuelle Beiträge

Alle ansehen

The Line Type Myth


bottom of page