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

save in excel file and send it to via mail to requested person via job queue.

(1) ShareShare
ReportReport
Posted on by 387

Dear Experts,

I have made a customized page in Navision, where dimension value table is involved. Now i want to export it in excel file format and send it to via email on every Wednesday to RND department. How can I implement in Navsion. Please give me idea to do that.

7802.png

I have the same question (0)
  • Suggested answer
    Marco Mels Profile Picture
    Microsoft Employee on at

    Hello,

    A suggestion may be to create a report and schedule it via job queue?

    Thanks.

  • navision begginers Profile Picture
    387 on at

    Hello sir,

    as per suggestion, I have develop the report. Report is running successfully and data is automatically exported in excel sheet. But please suggest me how I can send this excel file to concern via  email using job queue. Please give me an idea to write a code for excel email sending.

    pastedimage1608294908131v1.png

    pastedimage1608295002373v2.png

  • navision begginers Profile Picture
    387 on at

    my code are below:

    CLEAR(RDCodeReport); // RDCodeReport is a Report 50155
    EXCELDocPath :='R& D Code Report.xlsx'; //FileName
    RDCodeReport.USEREQUESTPAGE(FALSE);
    Path := 'C:\Temp\'+EXCELDocPath; // Directory + Path
    IF NOT RDCodeReport.SAVEASEXCEL(Path) THEN
    ERROR('EXCEL Creating Failed!\\ERROR:\\' + GETLASTERRORTEXT);
    SMTpMail.CreateMessage('XYZ Limited','NAV@xyz.com','xyz@test.com','R&D Code Report','',TRUE);
    SMTpMail.AppendBody('Dear Sir / Madam,');
    SMTpMail.AppendBody('<br><br>');
    SMTpMail.AppendBody('Please find the R&D Code Details in EXCEL Format:');
    SMTpMail.AppendBody('<br><br>');
    SMTpMail.AppendBody('Regards');
    SMTpMail.AppendBody('<br>');
    SMTpMail.AppendBody('XYZTesting & RND Departments');
    SMTpMail.AddAttachment(Path,EXCELDocPath);
    SMTpMail.Send;
    ERASE(Path);

  • navision begginers Profile Picture
    387 on at

    variables are below:

    pastedimage1608975783096v2.png

    Name DataType Subtype Length
    SMTpMail Codeunit SMTP Mail
    RDCodeReport Report R& D Code Report
    EXCELDocPath Text 250
  • navision begginers Profile Picture
    387 on at

    report code are below:

    Documentation()

    OnInitReport()

    OnPreReport()

    IF PrintToExcel THEN

     MakeExcelInfo;

    OnPostReport()

    IF PrintToExcel THEN

     CreateExcelbook;

    Dimension Value - OnPreDataItem()

    IntSr := 0;

    Dimension Value - OnAfterGetRecord()

    recCompanyInfo.GET();

    recCompanyInfo.CALCFIELDS(Picture);

    IntSr +=1;

    txtData[1] := FORMAT("Dimension Value".Code);

    txtData[2] := FORMAT("Dimension Value".Name);

    txtData[3] := FORMAT("Dimension Value".Description);

    txtData[4] := FORMAT("Dimension Value"."Enquiry No.");

    txtData[5] := FORMAT("Dimension Value"."Project Status");

    txtData[6] := FORMAT("Dimension Value"."R&D Type");

    txtData[7] := FORMAT("Dimension Value".Timeline);

    txtData[8] := FORMAT("Dimension Value"."Master Project No.");

    txtData[9] := FORMAT("Dimension Value".Blocked);

    IF PrintToExcel THEN

     MakeExcelDataBody;

    Dimension Value - OnPostDataItem()

    MakeExcelInfo()

    ExcelBuf.SetUseInfoSheet;

    ExcelBuf.AddInfoColumn(COMPANYNAME,FALSE,'',FALSE,FALSE,FALSE,'',ExcelBuf."Cell Type"::Text);

    ExcelBuf.NewRow;

    ExcelBuf.AddInfoColumn(USERID,FALSE,'',FALSE,FALSE,FALSE,'',ExcelBuf."Cell Type"::Text);

    ExcelBuf.NewRow;

    ExcelBuf.AddInfoColumn(TODAY,FALSE,'',FALSE,FALSE,FALSE,'',ExcelBuf."Cell Type"::Date);

    ExcelBuf.NewRow;

    ExcelBuf.ClearNewRow;

    MakeExcelDataHeader;

    MakeExcelDataHeader()

    ExcelBuf.NewRow;

    ExcelBuf.AddColumn('Project Code No.',FALSE,'',TRUE,FALSE,TRUE,'',ExcelBuf."Cell Type"::Text);

    ExcelBuf.AddColumn('Project Name',FALSE,'',TRUE,FALSE,TRUE,'',ExcelBuf."Cell Type"::Text);

    ExcelBuf.AddColumn('Description',FALSE,'',TRUE,FALSE,TRUE,'',ExcelBuf."Cell Type"::Text);

    ExcelBuf.AddColumn('Enquiry No.',FALSE,'',TRUE,FALSE,TRUE,'',ExcelBuf."Cell Type"::Text);

    ExcelBuf.AddColumn('Project Status',FALSE,'',TRUE,FALSE,TRUE,'',ExcelBuf."Cell Type"::Text);

    ExcelBuf.AddColumn('Project Completion Days',FALSE,'',TRUE,FALSE,TRUE,'',ExcelBuf."Cell Type"::Text);

    ExcelBuf.AddColumn('Expected Date',FALSE,'',TRUE,FALSE,TRUE,'',ExcelBuf."Cell Type"::Text);

    ExcelBuf.AddColumn('Promissed Date',FALSE,'',TRUE,FALSE,TRUE,'',ExcelBuf."Cell Type"::Text);

    ExcelBuf.AddColumn('Blocked',FALSE,'',TRUE,FALSE,TRUE,'',ExcelBuf."Cell Type"::Text);

    MakeExcelDataBody()

    ExcelBuf.NewRow;

    ExcelBuf.AddColumn(txtData[1],FALSE,'',FALSE,FALSE,FALSE,'',ExcelBuf."Cell Type"::Text);

    ExcelBuf.AddColumn(txtData[2],FALSE,'',FALSE,FALSE,FALSE,'',ExcelBuf."Cell Type"::Text);

    ExcelBuf.AddColumn(txtData[3],FALSE,'',FALSE,FALSE,FALSE,'',ExcelBuf."Cell Type"::Text);

    ExcelBuf.AddColumn(txtData[4],FALSE,'',FALSE,FALSE,FALSE,'',ExcelBuf."Cell Type"::Text);

    ExcelBuf.AddColumn(txtData[5],FALSE,'',FALSE,FALSE,FALSE,'',ExcelBuf."Cell Type"::Text);

    ExcelBuf.AddColumn(txtData[6],FALSE,'',FALSE,FALSE,FALSE,'',ExcelBuf."Cell Type"::Text);

    ExcelBuf.AddColumn(txtData[7],FALSE,'',FALSE,FALSE,FALSE,'',ExcelBuf."Cell Type"::Text);

    ExcelBuf.AddColumn(txtData[8],FALSE,'',FALSE,FALSE,FALSE,'',ExcelBuf."Cell Type"::Text);

    ExcelBuf.AddColumn(txtData[9],FALSE,'',FALSE,FALSE,FALSE,'',ExcelBuf."Cell Type"::Text);

    CreateExcelbook()

    ExcelBuf.CreateBookAndOpenExcel('',Text003,'',COMPANYNAME,USERID);

    ERROR('');

    InitializeRequest()

    //PrintToExcel := SetPrintToExcel;

  • Verified answer
    Binesh Profile Picture
    7,887 on at

    Hi,

    Add the below function  in the Table 370 excel buffer

    pastedimage1608983026149v2.png

    Add the below line of code instead of CreatBookAndOpenExcel

    ExcelBuf.CreateBookForJobQueue(SharedFileName,SheetName,'',COMPANYNAME,USERID);

    Make sure PrintToExcel and SharedFileName is assigned in OnPreReport Trigger as below

    OnPreReport()

    PrintToExcel  := true;

    SharedFileName := '\\Computername\foldername\filename.xlsx';  //Text Variable

    SheetName := 'Detail'; //Text variable

    Also in the report trigger OnPostReport

    OnPostReport() you can write a code to send an email for example

    IF PrintToExcel THEN BEGIN

     CreateExcelbook;

     SendMail();

    END;

    SendMail() // it is a function
    SMTpMail.CreateMessage('XYZ Limited','NAV@xyz.com','xyz@test.com','R&D Code Report','',TRUE);
    SMTpMail.AppendBody('Dear Sir / Madam,');
    SMTpMail.AppendBody('

    '); SMTpMail.AppendBody('Please find the R&D Code Details in EXCEL Format:'); SMTpMail.AppendBody('

    '); SMTpMail.AppendBody('Regards'); SMTpMail.AppendBody('
    '); SMTpMail.AppendBody('XYZTesting & RND Departments'); SMTpMail.AddAttachment(SharedFileName,SharedFileName); SMTpMail.Send;

    Also make sure to set the request page false and now you can setup this report in job queue.

  • navision begginers Profile Picture
    387 on at

    issue is resolved.

    you are genius.

  • AjayPandey Profile Picture
    133 on at

    Hi can you please send the full codes of mail codeunit.

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!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,055 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,063 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 1,014 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans