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 

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...