Skip to main content

Notifications

Announcements

No record found.

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

  • AjayPandey Profile Picture
    AjayPandey 133 on at
    RE: save in excel file and send it to via mail to requested person via job queue.

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

  • navision begginers Profile Picture
    navision begginers 387 on at
    RE: save in excel file and send it to via mail to requested person via job queue.

    issue is resolved.

    you are genius.

  • Verified answer
    Binesh Profile Picture
    Binesh 7,885 on at
    RE: save in excel file and send it to via mail to requested person via job queue.

    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
    navision begginers 387 on at
    RE: save in excel file and send it to via mail to requested person via job queue.

    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;

  • navision begginers Profile Picture
    navision begginers 387 on at
    RE: save in excel file and send it to via mail to requested person via job queue.

    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
    navision begginers 387 on at
    RE: save in excel file and send it to via mail to requested person via job queue.

    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
    navision begginers 387 on at
    RE: save in excel file and send it to via mail to requested person via job queue.

    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

  • Suggested answer
    Marco Mels Profile Picture
    Marco Mels on at
    RE: save in excel file and send it to via mail to requested person via job queue.

    Hello,

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

    Thanks.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans