Skip to main content

Notifications

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.

  • P V Sarath Profile Picture
    P V Sarath 130 on at
    RE: How to Export the Records

    Thank you, Nitin Verma.

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,091 Super User 2024 Season 1 on at
    RE: How to Export the Records

    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
    P V Sarath 130 on at
    RE: How to Export the Records

    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
    Nitin Verma 21,091 Super User 2024 Season 1 on at
    RE: How to Export the Records

    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
    P V Sarath 130 on at
    RE: How to Export the Records

    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
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,748 Super User 2024 Season 1 on at
    RE: How to Export the Records

    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?

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

News and Announcements

Announcing Category Subscriptions!

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,359 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans