I recently had assignment where I had XML file with ID’s and Base64 images and I had to import it against Business Central Records.

I thought it will take like an hour and I be done with it but it was more complicated then I thought.

So I thought I might share my solution if anybody needs to do the same.

The solution uses XmlPort and imports base64 as bigtext. Then its converted to blob and streamed into the employee.picture field which is also a blob.

pageextension 76104 "Extend Payroll Employee" extends "Payroll Employee List"
{
    actions
    {
        addafter("Working Register Export")
        {
            action("Import Empl. Pictures")
            {
                Caption = 'Import Employee pictures from file';
                Image = ImportExcel;
                ApplicationArea = All;
                trigger OnAction()
                begin
                    Xmlport.Run(Xmlport::ImportEmployeePictures, true, true);
                end;
            }
        }
    }
}

xmlport 76100 ImportEmployeePictures
{
    Format = Xml;
    FormatEvaluate = Xml;
    Caption = 'Import employee pictures';
    Direction = Import;
    UseRequestPage = false;
    schema
    {
        textelement(Root)
        {
            XmlName = 'employees';
            tableelement(XmlEmployee; Integer)
            {
                SourceTableView = SORTING(Number) WHERE(Number = CONST(1));
                XmlName = 'employee';
                UseTemporary = true;

                textelement(WD_ID)
                {
                    XmlName = 'WD_ID';
                }
                textelement(EmployeeNo)
                {
                    XmlName = 'table_number';
                }

                textelement(EmployeePicture)
                {
                    XmlName = 'image';
                    TextType = BigText;
                }

                trigger OnBeforeInsertRecord()
                var
                    PlkPayrollEmployee: Record "Payroll Employee";
                    Base64CU: codeunit "Base64 Convert";
                    Tempblob: Codeunit "Temp Blob";
                    ImageBase64Sring: Text;
                    OutStream: OutStream;
                    RecordRef: RecordRef;
                begin
                    if XmlEmployee.FindLast() then
                        XmlEmployee.Number += 1;

                    if PlkPayrollEmployee.Get(EmployeeNo) then begin

                        if PlkPayrollEmployee.Get(EmployeeNo) then begin
                            Tempblob.CreateOutStream(OutStream);
                                if (EmployeePicture.GetSubText(ImageBase64Sring, 1) < 0) then begin
                                    Base64CU.FromBase64(ImageBase64Sring, OutStream);
                                    RecordRef.GetTable(PlkPayrollEmployee);
                                    Tempblob.ToRecordRef(RecordRef, 10);
                                    RecordRef.Modify();
                                end;
                        end;
                    end;
                end;
            }
        }
    }
}