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 

Tuesday, September 2, 2014

Print PDF file from AX

Print PDF file from AX 

This job illustrates how we can print an external PDF file to a printer chosen in AX through X++ code. Here a code sample (X++ job) to do this.


static void theAxapta_pdfprint(Args _args)
{ 
    PrintJobSettings    printJobSettings = new PrintJobSettings(); 
    Dialog              dialog = new Dialog(); 
    DialogField         dialogFileName; 
    str                 adobeExe; 
    str                 adobeParm; 
;
    dialogFilename  = dialog.addField(typeid(FilenameOpen));

    if (dialog.run()) 
    {     
        printJobSettings.printerSettings('SysPrintForm');     
        adobeExe = WinAPI::findExecutable(dialogFileName.value());
       
        adobeParm = strFmt(' /t "%1" "%2" "%3" "%4"',
                           dialogFileName.value(),
                           printJobSettings.printerPrinterName(),
                           printJobSettings.printerDriverName(),
                           printJobSettings.printerPortName());

        winAPI::shellExecute(adobeExe,  adobeParm); 
    }
}

Wednesday, August 20, 2014

How to create new Number Sequence in Ax 2009

Steps to Create Number Sequence in Ax 2009

Step - 1
Create an EDT just like i have created 'ReasonCode'

Step 2
Go to the Module Table : SalesParameters
Create a method:
public client server static NumberSequenceReference numRefReasonCode()
{;
    return NumberSeqReference::findReference(typeId2ExtendedTypeId(typeid(ReasonCode)));

}

Step 3
Go to the module Class : NumberSeqReference_Customer
Select the LoadModule Method:
//Start
    numRef.DataTypeId                 = typeId2ExtendedTypeId(typeid(ReasonCode));
    numRef.ReferenceHelp            = literalstr("Reason Code");
    numRef.WizardContinuous         = False;
    numRef.WizardManual             = NoYes::No;
    numRef.WizardAllowChangeDown    = NoYes::No;
    numRef.WizardAllowChangeUp      = NoYes::No;
    numRef.WizardHighest            = 999999;
    numRef.SortField                = 418;
    this.create(numRef);  
//End

Step 4
Go to the Table :  Override initvalue method just like below
public void initValue()
{
    NumberSeq       NumSeq;
    ;
    super();
    NumSeq =  NumberSeq::newGetNum(SalesParameters::numRefReasonCode(),true);
    this.ReasonCode = NumSeq.num();
}

Step 5
Go to Module Parameter Form and select Number Sequence Tab, There is a line Created for Reason Code which is selected in Given Image


Step 6
Now Go To maint Table form of Number Sequence and Create a line for number sequence and select it for Reason Code as gshown in below image

Step 7
Now Your number sequence setting is up to date and you can create record in form as shown in below image

Thats All!!



Thanks






Wednesday, July 9, 2014

Thursday, June 26, 2014

Open Axapta form in Maximize mode

If we want to open any Ax form in Maximize mode than we have to create a Run method of form as Below

public void run()
{
    #WinApi
    ;
    super();
    WinApi::showWindow(this.hWnd(), #SW_SHOWMAXIMIZED);
}


Thanks

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