Skip to main content

Notifications

Business Central forum
Suggested answer

How to Import Blob Field using Excel Buffer in business central.

Posted on by 95

I want to import Blob fields into my custom  "Service Worksheet Table".all data imported but Blob Field Data not Inserted into table.

please give me suggestion How to achieve this. 

 blob fields.

1.Fault Comment Line
2.Resolution Comment Line
3.Internal Comment Line

  local procedure ImportExcelData()
    var
        SOImportBuffer: Record "ST_Service Worksheet LineTable";
        RowNo: Integer;
        ColNo: Integer;
        LineNo: Integer;
        MaxRowNo: Integer;
    begin
        RowNo := 0;
        ColNo := 0;
        MaxRowNo := 0;
        LineNo := 0;
        SOImportBuffer.Reset();
        if SOImportBuffer.FindLast() then
            LineNo := SOImportBuffer."Line No.";
        TempExcelBuffer.Reset();
        if TempExcelBuffer.FindLast() then begin
            MaxRowNo := TempExcelBuffer."Row No.";
        end;

        for RowNo := 2 to MaxRowNo do begin
            LineNo := LineNo   10000;
            SOImportBuffer.Init();

            SOImportBuffer."Line No." := LineNo;
            Evaluate(SOImportBuffer."Serial No.", GetValueAtCell(RowNo, 1));
            Evaluate(SOImportBuffer."Service Item No.", GetValueAtCell(RowNo, 2));
            Evaluate(SOImportBuffer."Customer No.", GetValueAtCell(RowNo, 3));
            Evaluate(SOImportBuffer."Customer Name", GetValueAtCell(RowNo, 4));
            Evaluate(SOImportBuffer."Ship-to Code", GetValueAtCell(RowNo, 5));
            Evaluate(SOImportBuffer."Shipment No.", GetValueAtCell(RowNo, 6));
            Evaluate(SOImportBuffer."Shipment Date", GetValueAtCell(RowNo, 7));
            Evaluate(SOImportBuffer."Item No.", GetValueAtCell(RowNo, 8));
            Evaluate(SOImportBuffer.Description, GetValueAtCell(RowNo, 9));
            Evaluate(SOImportBuffer."Description 2", GetValueAtCell(RowNo, 10));
            Evaluate(SOImportBuffer."Fault Area Code", GetValueAtCell(RowNo, 11));
            Evaluate(SOImportBuffer."Symptom Code", GetValueAtCell(RowNo, 12));
            Evaluate(SOImportBuffer."Fault Code", GetValueAtCell(RowNo, 13));
            Evaluate(SOImportBuffer."Resolution Code", GetValueAtCell(RowNo, 14));
            Evaluate(SOImportBuffer."No. of Previous Services", GetValueAtCell(RowNo, 15));
            Evaluate(SOImportBuffer."Service Order No.", GetValueAtCell(RowNo, 16));
            Evaluate(SOImportBuffer."Fault Comment Line", GetValueAtCellBlob(RowNo, 17));
            Evaluate(SOImportBuffer."Resolution Comment Line", GetValueAtCellBlob(RowNo, 18));
            Evaluate(SOImportBuffer."Internal Comment Line", GetValueAtCellBlob(RowNo, 19));
            SOImportBuffer."Sheet Name" := SheetName;
            SOImportBuffer."File Name" := FileName;

            SOImportBuffer.Insert();
        end;
        Message(ExcelImportSucess);
    end;

    local procedure GetValueAtCell(RowNo: Integer; ColNo: Integer): Text
    begin

        TempExcelBuffer.Reset();
        If TempExcelBuffer.Get(RowNo, ColNo) then
            exit(TempExcelBuffer."Cell Value as Text")
        else
            exit('');
    end;

    local procedure GetValueAtCellBlob(RowNo: Integer; ColNo: Integer): Text
    var
        CellTextValue: text;
        RecInStream: InStream;
        TempBlob: Codeunit "Temp Blob";
        TypeHelper: Codeunit "Type Helper";
        InStream: InStream;
        Faultcomm: text;
    begin
        TempExcelBuffer.Reset();
        If TempExcelBuffer.get(RowNo, ColNo) then begin
            CalcFields("Fault Comment Line");
            "Fault Comment Line".CreateInStream(InStream, TEXTENCODING::UTF8);
        end;
    end;

Categories:
  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,744 Moderator on at
    RE: How to Import Blob Field using Excel Buffer in business central.

    Your GetValueAtCellBlob function is missing an exit statement.

    You need to add

    Exit(YourTxtValue);

    If not the return value will always be empty.

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,023 Moderator on at
    RE: How to Import Blob Field using Excel Buffer in business central.

    Hi,

    Please refer below links to get some idea how to work with blob fields. I hope it will help you.

    https://demiliani.com/2020/01/24/dynamics-365-business-central-handling-blob-fields-on-apis/

    https://subscription.packtpub.com/book/business-and-other/9781789951257/8/ch08lvl1sec46/reading-and-writing-text-data-to-and-from-blob-fields

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,522 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,441 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans