Skip to main content

How to send Normal AX Reports to User through Batch Process in Dynamics Ax 2009.


Hi friends,
Recently I got one requirements from my User, I.e. customer want to see ax reports in E-mail everyday once through batch process.
its just like send mail from batch process only, But we need to work on how to send normal report.

1) write the class with below methods mandatory.
         


2)Here am going to post logic for how to convert ax report to PDF and how to send the email to user only.

// Saved the reports into particular location
void SaveReport()
{
    Args args;
    ReportRun rr;
    str reportName = "OpenPurchOrderLine_Vendor";
    str myPath;
    int i;
   ;
   i = 1;
  args = new Args(reportName);
  args.caller(rr);
  rr = new reportRun(args);
    rr.query().interactive(false);
    rr.report().interactive(false);
    rr.setTarget(printMedium::File);
    rr.printJobSettings().setTarget(PrintMedium::File);
    rr.printJobSettings().preferredTarget(PrintMedium::File);
    rr.printJobSettings().format(PrintFormat::PDF);
    rr.printJobSettings().warnIfFileExists(false);
    rr.printJobSettings().suppressScalingMessage(true);
    pdfFileName = @\\AXTESTDEV1\D$\Test\test.pdf; //@ is used for server\\ServerName\drive name$\Folder
    rr.printJobSettings().fileName(pdfFileName);
    rr.init();
    rr.run();
    info("After Run in SaveReport()");
}

//Used to sending emails to particular users

void EmailCheck()
{
         //Set                     permissionSet2 = new Set(Types::Class);
         InteropPermission permission = new InteropPermission(InteropKind::ComInterop);
         ;
        CodeAccessPermission::revertAssert();
        info("After code access in EmailCheck()");
         permission.assert();
         mailer = new SysMailer();
         parameters = SysEmailParameters::find();
        if (parameters.SMTPRelayServerName)
       {
            mailer.SMTPRelayServer(parameters.SMTPRelayServerName,
                         parameters.SMTPPortNumber,
                         parameters.SMTPUserName,
                         SysEmailParameters::password(),
                         parameters.NTLM);
             info("if");
       }
      else
      {
        mailer.SMTPRelayServer(parameters.SMTPServerIPAddress,
                             parameters.SMTPPortNumber,
                             parameters.SMTPUserName,
                             SysEmailParameters::password(),
                             parameters.NTLM);
                  info("else");
        }
        mailer.fromAddress('xyz@abc.com');
       mailer.tos().appendAddress('abc@xyz.com');
       mailer.tos().appendAddress('TEST@company.com');
      mailer.htmlBody('Find the attachment.
                         <Br>\n NOTE:This is a System Generated Email. Please do not Reply.');
      mailer.subject('Report Attached(Testing Mail)');
      info(pdfFileName);
      mailer.attachments().add("D:\\Test\\test.pdf");
       mailer.sendMail();
       CodeAccessPermission::revertAssert();
}
Next Configure this class into batch Job User Form.....
If any clarification or issues please comments to this..
Happy
Daxing...
  

Comments

  1. Thank you its very useful post.

    What if I do not want to hard code the user email-id's....?

    How can I select email id's dynamically....?

    ReplyDelete
  2. As per my thoughts if you want to select the email ids manually,U Know we need to create the form with email ids like parameter form,There we have to select the mail ids ,while running the batch process system goes to that table and pick the email id'.....

    ReplyDelete
  3. kindly i need to know how to run this as a scheduled batch
    also this line gives me an error
    CodeAccessPermission::revertAssert();

    ReplyDelete
    Replies
    1. Hi Hamdi,

      Kindly check the below links for batch processing ..and you said you are getting error right ,i think so can you please check if you useing below versions in ax2009.the problem with RollUps...

      http://axhelpdesk.blogspot.com/2013/03/how-to-send-emails-to-users-in-batch.html

      Thanks
      Brahma

      Delete
  4. Suppose if I want to save a Sales Invoice as PDF, how can I do it?

    ReplyDelete

Post a Comment

Popular posts from this blog

Using File path on a form getting Error in Axapta

Hi Folks, After a long time am coming  back to posting few new things here for AX Developer... When we want to select the file path in form level. Normally what we will do create one EDT and extends with filepath (EDT), but that time when you are trying to select the path we will get error like stack-trace/Error message .Don’t worry there is no problem with your ax application. Simple we need to provide the method to the form like filepathLookUpTitle (). Below method we need to add it into form level methods, i.e. str filePathLookupTitle() {     return "Select document folder"; } Thanks Happy Daxing....

How to add Filter functionality to Display method in dynamics AXAPTA

Hi Friends, Normally filters will work only in table fields but we can't do filters to display method. This below code will work for filters to display method also. Step 1: Go to the form design right click on particular control properties Auto Declaration No to Yes. Step 2: Override the context() method on the display method  . public void context() {     int             selectedMenu;     formrun         fr;     Args            ag;     Name            strtext;     querybuilddataSource qb1;     queryrun    qr;     query       q;     PopupMenu menu = new PopupMenu(element.hWnd());     int a = menu.insertItem('Filter By Field');     int b = menu.insertItem('Filter By Selection');     i...

Split string useing List in AX2009

static void Job277(Args _args) {     List _list = new List(Types::String);     Container packedList;     ListIterator iterator;     str cade = "Jhon*,smt*,and*,caro*";     ;     _list = Global::strSplit(cade,",");     iterator = new ListIterator(_list);     while(iterator.more())     {         packedList += iterator.value();         iterator.next();     }     info(conpeek(packedList,2));     info(strfmt("%1",conlen(packedList)));   }