web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

How to Export the Records

(0) ShareShare
ReportReport
Posted on by 130

Hi All,

        I am Exporting the Vendor Records by using the Excel Buffer, but I am getting this error, can anyone help me.

pastedimage1663477982564v1.png

Thanks & Regards

P V Sarath.

I have the same question (0)
  • Suggested answer
    IB-29041624-0 Profile Picture
    1,191 Moderator on at

    It seems that you are violating the primary key in the table.

    Make sure you increment the row and or column number for every new insert.

    Maybe you you can share your code so we can easier help you figure out your problem?

  • P V Sarath Profile Picture
    130 on at

    Hi Bruvik,

                   I am sharing my code I am calling from the functions from codeunit in the report.

     procedure MakeVendor()
        var
            TempExcelBuffer: Record "Excel Buffer";
        // "Vendor No.":Code[20];
        begin
            TempExcelBuffer.NewRow();
            TempExcelBuffer.AddColumn('Vendor No.', false, '', true, false, true, '', TempExcelBuffer."Cell Type"::Text);
            TempExcelBuffer.AddColumn('Vendor Name', false, '', true, false, true, '', TempExcelBuffer."Cell Type"::Text);
            TempExcelBuffer.AddColumn('Vendor Address', false, '', true, false, true, '', TempExcelBuffer."Cell Type"::Text);
        end;

        procedure MakeBody()
        var
            TempExcelBuffer: Record "Excel Buffer";
            Vendor: Record Vendor;
        begin
            TempExcelBuffer.NewRow();
            TempExcelBuffer.AddColumn(Vendor."No.", false, '', false, false, false, '', TempExcelBuffer."Cell Type"::Text);
            TempExcelBuffer.AddColumn(Vendor.Name, false, '', false, false, false, '', TempExcelBuffer."Cell Type"::Text);
            TempExcelBuffer.AddColumn(Vendor.Address, false, '', false, false, false, '', TempExcelBuffer."Cell Type"::Text);
        end;

        procedure CreateExcel()
        var
            TempExcelBuffer: Record "Excel Buffer";
        begin
            TempExcelBuffer.CreateNewBook('Vendors');
            TempExcelBuffer.WriteSheet('Vendor', CompanyName, UserId);
            TempExcelBuffer.CloseBook();
            TempExcelBuffer.SetFriendlyFilename('Vendors');
            TempExcelBuffer.OpenExcel();
        end;
    I am calling these functions in the Report Triggers, and through the Action I am calling this,
     action(ExportVendor)
                {
                    ApplicationArea = All;
                    Caption = 'ExportVendor';
                    ToolTip = 'Exports the Selected Vendors';
                    trigger OnAction()
                    var
                        EmployeeCreation: Report "Create Employee in Vendor VEL";
                    begin
                        EmployeeCreation.Run();
                        Message('process Finished');
                    end;
    Can you please guide me where I am wrong in this, 
    Thanks & Regards,
    P V Sarath.
  • Suggested answer
    Nitin Verma Profile Picture
    21,812 Moderator on at

    Hi,

    Please create your own function to enter the values in Cell instead of Addcolumn functions

    RowNo : Integer

    RowNo := 1;

    EnterCell(RowNo : Integer;ColumnNo : Integer;CellValue : Text[250];Bold : Boolean;Italic : Boolean;UnderLine : Boolean;DoubleUnderLine : Boolean;Format : Text[30];CellType : Option)

    TempExcelBuffer.INIT;
    TempExcelBuffer.VALIDATE("Row No.",RowNo);
    TempExcelBuffer.VALIDATE("Column No.",ColumnNo);
    TempExcelBuffer."Cell Value as Text" := CellValue;
    TempExcelBuffer.Formula := '';
    TempExcelBuffer.Bold := Bold;
    TempExcelBuffer.Italic := Italic;
    IF DoubleUnderLine = TRUE THEN BEGIN
    TempExcelBuffer."Double Underline" := TRUE;
    TempExcelBuffer.Underline := FALSE;
    END ELSE BEGIN
    TempExcelBuffer."Double Underline" := FALSE;
    TempExcelBuffer.Underline := UnderLine;
    END;TempExcelBuffer.NumberFormat := Format;
    TempExcelBuffer."Cell Type" := CellType;
    TempExcelBuffer.INSERT;

     procedure MakeVendor()
        var
            TempExcelBuffer: Record "Excel Buffer";
        // "Vendor No.":Code[20];
        begin
            Row := 1;
            Column := 1;
            EnterCell(RowNo,ColumnNo,Vendor.No.,Bold,Italic,UnderLine,DoubleUnderLine,Format,CellType
            Column += 1;
            EnterCell(RowNo,ColumnNo,Vendor.No.,Bold,Italic,UnderLine,DoubleUnderLine,Format,CellType
            Column += 1;
            EnterCell(RowNo,ColumnNo,Vendor.No.,Bold,Italic,UnderLine,DoubleUnderLine,Format,CellType
        end;

  • P V Sarath Profile Picture
    130 on at

    Hi All,

               For Expporting a file, I am calling my function in the codeunit Run trigger, my code is 

              

    local procedure GenerateFile()
        var
            Instr: InStream;
            Outstr: OutStream;
            TempBlob: Codeunit "Temp Blob";
            FileName: Text;
        begin
            TempBlob.CreateOutStream(Outstr);
            Xmlport.Export(Xmlport::"Vendor Export VEL", Outstr);
            TempBlob.CreateInStream(Instr);
            FileName := 'Vendors.xml';
            DownloadFromStream(Instr, '', '', '', FileName);
        end;
        I am calling this codeunit in the action, 
          
     action(ExportVendor)
                {
                    ApplicationArea = All;
                    Caption = 'ExportVendor';
                    ToolTip = 'Exports the Selected Vendors';
                    trigger OnAction()
                    var
                        UpdateRecords: Codeunit "Update Records VendorEmployee";
                        EmployeeCreation: Report "Create Employee in Vendor VEL";
                    begin
                          UpdateRecords.Run();
                        Message('process Finished');
                    end;

    But, I am getting this error, can anyone guide me please.

    pastedimage1663566978541v1.png

    Thanks & Regards,

    P Venkata Sarath.

  • Suggested answer
    Nitin Verma Profile Picture
    21,812 Moderator on at

    Hi,

    Please use as Yellow marked

    local procedure GenerateFile()
        var
            Instr: InStream;
            Outstr: OutStream;
            TempBlob: Codeunit "Temp Blob";
            FileName: Text;
        begin
            TempBlob.CreateOutStream(Outstr);
            Xmlport.Export(Xmlport::"Vendor Export VEL", Outstr);
            TempBlob.CreateInStream(Instr);
            FileName := 'Vendors.xml';
            DownloadFromStream(Instr, '''''', FileName);
        end;
        I am calling this codeunit in the action, 
          
     action(ExportVendor)
                {
                    ApplicationArea = All;
                    Caption = 'ExportVendor';
                    ToolTip = 'Exports the Selected Vendors';
                    trigger OnAction()
                    var
                        UpdateRecords: Codeunit "Update Records VendorEmployee";
                        EmployeeCreation: Report "Create Employee in Vendor VEL";
                    begin
                          Commit;
                          UpdateRecords.Run();
                        Message('process Finished');
                    end;
  • P V Sarath Profile Picture
    130 on at

    Thank you, Nitin Verma.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,260 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,515 Super User 2026 Season 1

#3
AndrewThomas81 Profile Picture

AndrewThomas81 1,373

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans