Skip to main content

Notifications

Business Central forum
Answered

How to Export the Records

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.

Categories:
  • 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,023 Moderator 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,023 Moderator 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,744 Moderator 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

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