Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / Email Freetext invoice...
Finance forum

Email Freetext invoice via X++

(0) ShareShare
ReportReport
Posted on by 6,603

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!

  • Verified answer
    Sukrut Parab Profile Picture
    Sukrut Parab 71,656 Moderator on at
    RE: Email Freetext invoice via X++

    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

  • bankk Profile Picture
    bankk 6,603 on at
    RE: Email Freetext invoice via X++

    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!

  • Suggested answer
    Sukrut Parab Profile Picture
    Sukrut Parab 71,656 Moderator on at
    RE: Email Freetext invoice via X++

    Did you try following line of code  ?

    settings.emailTo(EmailRecipient);

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

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans