Thursday, November 6, 2014

Send report pdf as email in ax 2009 using batch job configuration

Hi friends,

if you want to send your report pdf as email to user through batch job than below code important for you.

First we have make a class for batch job configuration.

After it we have to save the file to server in a share folder using below method.


Static void SaveReport(str fileName)
{
    fileName = @'\\myPc\\testfile.pdf'; // it should be in UNC format
    Args                args = new Args("PMExceptionReport");
    reportRun reportRun = new reportRun(args);
    ;

    reportRun.query().interactive(False);
    reportRun.report().interactive(False);
    reportRun.setTarget(printMedium::File);
    reportRun.printJobSettings().setTarget(PrintMedium::File);
    reportRun.printJobSettings().preferredTarget(PrintMedium::File);
    reportRun.printJobSettings().format(PrintFormat::PDF);

    reportRun.printJobSettings().warnIfFileExists(False);
    reportRun.printJobSettings().suppressScalingMessage(True);
    reportRun.printJobSettings().packPrintJobSettings();
    reportRun.printJobSettings().fileName(filename);
    reportRun.run();
    //info("Done");
}

if our file is saved to shared folder than we can send it as mail attachment and for it code is listed below

static void SendMail(str email, str filename)
{
    InteropPermission permission = new InteropPermission(InteropKind::ComInterop);
    SysMailer   mailer;
    SysEmailParameters parameters;
    ;

    CodeAccessPermission::revertAssert();
    permission.assert();
    mailer = new SysMailer();
    parameters = SysEmailParameters::find();

    if (parameters.SMTPRelayServerName)
    {
        mailer.SMTPRelayServer(parameters.SMTPRelayServerName, parameters.SMTPPortNumber, parameters.SMTPUserName, SysEmailParameters::password(), parameters.NTLM);
    }
    else
    {
        mailer.SMTPRelayServer(parameters.SMTPServerIPAddress, parameters.SMTPPortNumber, parameters.SMTPUserName, SysEmailParameters::password(), parameters.NTLM);
    }

    mailer.fromAddress('donotreply@wondercement.com');
    mailer.tos().appendAddress(email);

    mailer.htmlBody('Please find attached exception report. <Br>\n do not reply this mail.');
    mailer.subject('Exception Report');
    mailer.attachments().add(filename);
    mailer.sendMail();

    CodeAccessPermission::revertAssert();
}


Printing reports from a server can be more efficient than printing from a client. When printing a report from a client, Microsoft Dynamics AX must upload details about page size, report dimensions, fonts, and string sizes to the client before the report can print. When printing a report from a server, these details are readily available. No extra processing is required.
To enable users to print reports from the server, you must configure the AOS server and each client.
Complete the following steps on the AOS server:
  1. Open the Server Configuration Utility (Start > All Programs > Microsoft Dynamics AX).
  2. Select the Allow clients to connect to printers on this server option.
  3. Click OK.
Complete the following steps on each client computer:
  1. Open the Client Configuration Utility (Start > All Programs > Microsoft Dynamics AX).
  2. Click the Connection tab.
  3. Select Connect to printers on the server.
  4. Click OK.

Thanks
B K 

1 comment:

  1. Here is Mr Benjamin contact Email details, 247officedept@gmail.com. /  Or Whatsapp +1 989-394-3740 that helped me with loan of 90,000.00 Euros to startup my business and I'm very grateful,It was really hard on me here trying to make a way as a single mother things hasn't be easy with me but with the help of Mr Benjamin put smile on my face as i watch my business growing stronger and expanding as well.I know you may surprise why me putting things like this here but i really have to express my gratitude so anyone seeking for financial help or going through hardship with there business or want to startup business project can see to this and have hope of getting out of the hardship..Thank You.

    ReplyDelete

Customer transaction automatic settlement for specific customer groups only

Hi Friends, Recently I come to the requirement of my company where I have to automatic settle the customer transaction for the speci...