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 :
Microsoft Dynamics AX (Archived)

How to send a report as mail(PDF) ?

(0) ShareShare
ReportReport
Posted on by

Hi All,

I am trying to send a report as an attachment to the user 

Ap->payment Journal ->lines ->print ->new button.

while user selects the line record and click on the new button .the system automatically send the selected record report as a pdf .directly to the end-user using controller class.

so can one provided me a sample code how to do that ???

Thanks in advance !!!

*This post is locked for comments

I have the same question (0)
  • kvnkk Profile Picture
    800 on at
    By using sample code you can build your own logic.. this is only a template



    Exportfile for AOT version 1.0 or later Formatversion: 1 ***Element: CLS ; Microsoft Dynamics AX Class: TestNotification unloaded ; -------------------------------------------------------------------------------- CLSVERSION 1 CLASS #TestNotification PROPERTIES Name #TestNotification Origin #{C91DC191-A9B2-4F83-96F1-3CD1C5B0ACC5} ENDPROPERTIES METHODS SOURCE #classDeclaration #class TestNotification #{ # TestTable TestTable; #} ENDSOURCE SOURCE #run #public void run() #{ # str 100 email = "Test@gmail.com" ; # str filepathname; # # # # filepathname = TestNotification::printTestReport(testtable); # # try # { # TestNotification::sendemailtestReport(email,"Test notification","Please find attached Report",filepathname); # # } # catch(Exception::Error) # { # # } # #} ENDSOURCE SOURCE #main #public static void main(Args _args) #{ # TestNotification TestNotification = new TestNotification(); # TestNotification.run(); #} ENDSOURCE SOURCE #printTestReport #public static str 255 printTestReport(testtable testtable) #{ # TestReport TestReportController; # # Args args = new Args(); # ReportName reportName = "TestReport.Report"; //Report Desinge name # str filepath = "filepath" + "testreport"+ ".pdf"; //Provide File path # # SrsPrintMgmtExecutionInfo printMgmtExecutionInfo; # TestContract TestContract; # # # # args.record(testtable); # # # TestReportController = new TestReport(); # TestReportController.parmReportName(reportName); # TestContract = TestReportController.parmReportContract().parmRdpContract(); # # TestContract.parmWorkerRecId(hcmWorker.RecId); # # TestReportController.parmExecutionMode(sysoperationexecutionmode::Synchronous); # TestReportController.parmReportContract().parmPrintSettings().printMediumType(SRSPrintMediumType::File); # TestReportController.parmReportContract().parmPrintSettings().overwriteFile(true); # TestReportController.parmReportContract().parmPrintSettings().fileFormat(SRSReportFileFormat::PDF); # TestReportController.parmReportContract().parmPrintSettings().fileName(filepath); # TestReportController.parmExecutionMode(sysoperationexecutionmode::Synchronous); # TestReportController.parmReportContract().parmRdlContract().parmLanguageId('en-us'); # # # # TestReportController.parmReportContract().parmReportExecutionInfo(new SrsPrintMgmtExecutionInfo()); # TestReportController.parmReportName(reportName); # TestReportController.parmArgs(args); # TestReportController.run(); # # # return filepath; # # #} ENDSOURCE SOURCE #sendemailtestReport #public static void sendemailtestReport(str _receipient,str _subject,str _body,str _filepath='C:\\test\\Default.txt', str _copy='') #{ # Args args = new Args(); # SrsReportRunImpl srsReportRun; # str filepath = _filepath; # str sender = 'sender@gmail.com'; # str recipient = _receipient; # str cc1 ,copy; # str subject = _subject; # str body = _body; # Set permissionSet; # System.Exception e; # str mailServer; # # System.Net.Mail.SmtpClient mailClient; # System.Net.Mail.MailMessage mailMessage; # System.Net.Mail.MailAddress mailFrom; # System.Net.Mail.MailAddress mailTo; # System.Net.Mail.MailAddressCollection mailCCCollection,mailtocollection; # System.Net.Mail.Attachment mailAttachment= new System.Net.Mail.Attachment(_filepath); # System.Net.Mail.AttachmentCollection mailAttachementCollection; # # str password= SysEmailParameters::password(); # SysEmailParameters SysEmailParameters = SysEmailParameters::find(); # SrsPrintMgmtExecutionInfo printMgmtExecutionInfo; # # container con; # int counted; # int conlength; # str emails; # # con = str2con(recipient,';'); # conlength = conLen(con); # # # # if (_copy) # { # cc1=_copy; # } # # sender = SysEmailParameters.SMTPUserName; # # try # { # permissionSet = new Set(Types::Class); # permissionSet.add(new InteropPermission(InteropKind::ClrInterop)); # CodeAccessPermission::assertMultiple(permissionSet); # mailServer = SysEmaiLParameters::find(false).SMTPRelayServerName; # mailClient = new System.Net.Mail.SmtpClient(mailServer); # mailClient.set_EnableSsl(false); # mailFrom = new System.Net.Mail.MailAddress(sender); # # for (counted =1;counted <= conlength;counted++) # { # copy = conPeek(con,counted); # # if (copy =='') # { # continue; # } # if (counted ==1) # { # mailTo = new System.Net.Mail.MailAddress(copy); # mailMessage = new System.Net.Mail.MailMessage(mailFrom, mailTo); # } # else # { # mailtocollection = mailMessage.get_To(); # mailtocollection.Add(copy);} # } # # # if (cc1) # { # con = str2con(cc1,';'); # conlength = conLen(con); # for (counted =1;counted <= conlength;counted++) # { # copy = conPeek(con,counted); # # if (copy =='') # { # continue; # } # mailCCCollection = mailMessage.get_CC(); # mailCCCollection.Add(copy); # } # } # # if(!mailMessage) # { # return; # } # mailMessage.set_Priority(System.Net.Mail.MailPriority::High); # mailMessage.set_Subject(subject); # mailMessage.set_Body(body); # mailMessage.set_IsBodyHtml(true); # mailClient.set_UseDefaultCredentials(false); # # if (WinAPI::fileExists(_filepath)) # { # # mailAttachementCollection = mailMessage.get_Attachments(); # mailAttachementCollection.Add(mailAttachment); # } # # mailClient.set_Credentials(New System.Net.NetworkCredential(SysEmailParameters.SMTPUserName,Password)); # # mailClient.Send(mailMessage); # mailMessage.Dispose(); # CodeAccessPermission::revertAssert(); # # } # catch (Exception::CLRError) # { # e = ClrInterop::getLastException(); # while (e) # { # info(e.get_Message()); # e = e.get_InnerException(); # } # CodeAccessPermission::revertAssert(); # } #} ENDSOURCE ENDMETHODS ENDCLASS ***Element: END

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!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 39

#2
Michel ROY Profile Picture

Michel ROY 14

#3
imran ul haq Profile Picture

imran ul haq 8

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans