Hi folks!
I will show you how to create a CommandButton in a form able to launh a SSRS report in Report Viewer from AX 2009 with parameter passing.
Picture yourself that we have a SSRS report with a parameter called "test", and this parameter must be taken from the datasource table of the form.
All you have to do is create a CommandButton control in your form and override the "clicked" method with this code:
void clicked()
{
//declare the parameter
str _test;
;
//assign to the parameter the value of the datasource field
_test = YourTableName.YourFieldName;
infoLog.urlLookup(
strfmt("http://<yourServername>/<yourReportWebServiceName>/Pages/ReportViewer.aspx?/<yourReportName>&rs:Command=Render&<Test>=%1",_test));
super();
}
This command will open your browser and automatically launch the report with the specified parameter.
Sometimes I noticed visualization problems with browser different from Internet Explorer.
If Internet Explorer isn't the default browser, just change the command "infolog.urlLookup()" with:
WinAPI::shellExecute("iexplore.exe",strfmt("http://<yourServername>/<yourReportWebServiceName>/Pages/ReportViewer.aspx?/<yourReportName>&rs:Command=Render&<Test>=%1",_test),"","",1);
That's all!
...if users don't go to AX, AX will go to the users...! a blog about Dynamics AX tips and tricks, Sharepoint and Reporting Services
Monday, November 18, 2013
Monday, January 14, 2013
How to send a report via email from AX 2009
Hi all!
Today I want to show you how to send a custom report via email from AX (it works with an AX client installation and it's tested for Microsoft Outlook and Novell GroupWise).
In AX there is a class that allows you to do this: "SysINetMail".
Here's the code:
void printPDFMail()
{
SysINetMail SysINetMail;
str FileName;
str user;
str Body;
str Subject;
str cc1;
str mailAddressFrom;
str mailAddressTo;
UserInfo userInfo;
SysINetMail mail = new SysINetMail();
;
select firstonly userInfo where userInfo.id==curUserId(); {
user= userInfo.networkAlias; }
FileName = strfmt('C:\\Users\\%1\\Desktop\\AXReportName.pdf',user);
reportRun.printJobSettings().setTarget(PrintMedium::File);
reportRun.printJobSettings().format(PrintFormat::PDF);
reportRun.printJobSettings().fileName(FileName);
reportRun.run();
//assign the values of sender, recipient, subject and message body
Subject = 'Insert here the email subject';
Body = 'Insert here the email body';
cc1 = 'example@example.com';
//assign the values to send email
mailAddressFrom = SysUserInfo::find(curUserId()).Email;
mailAddressTo = email@addresstosend.com
//Send Mail
mail.sendMailAttach(mailAddressTo,cc1,Subject,Body,false,FileName);
//delete the temporary pdf file
winAPI::deleteFile(FileName);
//info("Email sent.");
}
I have included this method in a class that creates the report to be sent, but if you want to use it as a job, you have to use "Args" function to pass the name of the report to be printed.
Subscribe to:
Posts (Atom)