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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Forums / Finance forum / Email Freetext invoice...
Finance forum

Email Freetext invoice via X++

(0) ShareShare
ReportReport
Posted on by 6,609

Hello:

I have the code below to generate a free text invoice. 

CustInvoiceJour custInvoiceJourLocal = CustInvoiceJour::findRecId(5637916829);
Args args = new Args();
args.record(custInvoiceJourLocal);
new MenuFunction(menuitemOutputStr(FreeTextInvoiceOriginal), MenuItemType::Output).run(args);

My question is if it's possible to pass along print settings to be able to email the invoice to a specific address? I've tested the code snippet below and it does allow email, but in the context of the code above, I'm not sure if it can be used.

SRSPrintDestinationSettings settings = controller.parmReportContract().parmPrintSettings();
SrsReportEMailDataContract emailContract = new SrsReportEMailDataContract();
emailContract.parmTo(testEmailString);
emailContract.parmSubject("Invoice");
emailContract.parmBody(strFmt("Hi there! Here is your invoice. Invoice#:%1", custInvoiceJour.InvoiceId));
emailContract.parmAttachmentFileFormat(SRSReportFileFormat::PDF);
settings.printMediumType(SRSPrintMediumType::Email);
settings.fileFormat(SRSReportFileFormat::PDF);
settings.fileName(strFmt("%1", custInvoiceJour.InvoiceId));
settings.parmEMailContract(emailContract);

Any help would be appreciated. Thank you!

I have the same question (0)
  • Suggested answer
    Sukrut Parab Profile Picture
    71,710 Moderator on at

    Did you try following line of code  ?

    settings.emailTo(EmailRecipient);

  • bankk Profile Picture
    6,609 on at

    Hi Sukrut,

    I'm sorry, I probably confused it by including the second snippet of code. I guess back to the original question, if I were using this code to run the report...

    CustInvoiceJour custInvoiceJourLocal = CustInvoiceJour::findRecId(5637916829);

    Args args = new Args();

    args.record(custInvoiceJourLocal);

    new MenuFunction(menuitemOutputStr(FreeTextInvoiceOriginal), MenuItemType::Output).run(args);

    ...can I pass along settings to generate a PDF and email it? I would like to do this all through X++ and not use any print management settings.

    Thank you!

  • Verified answer
    Sukrut Parab Profile Picture
    71,710 Moderator on at

    Yes , you can do that . When you run report through args like what you are doing in your first snippet  , pass that args  to controller  like below

    controller.parmArgs(_args);

    then you are going to get contract from the controller and run the report

    contract        = controller.parmReportContract();

    then save report in the archive using second code snippet you posted in your original post

    printSettings = contract.parmPrintSettings();

           printSettings.overridePrintContractSettings(true);

           printSettings.printMediumType(SRSPrintMediumType::Archive);

           printSettings.parmOverwriteFileIsSet(true);

           printSettings.fileFormat(SRSReportFileFormat::PDF);

           printSettings.parmSRSPrintArchiveContract(archiveContract);

    get the report from archive and attached in the email . You can take below my blog as a reference , it was  written long time back but should be good to know about how you can save it to archive and get it to stream and attached to email.

    community.dynamics.com/.../d365fo-send-report-as-email-attachment

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Finance

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans