Thursday, December 27, 2012

Kirim email dari AX 2009

Catatan: mailTo hanya bisa diisi 1 email, bila lebih, maka hanya email yg pertama saja yg diproses.

void Send_Emailx(str subjectx,str bodyx,str sendtomailx,str sendtonamex)
{

    System.Net.Mail.MailMessage             mailMessage;
    System.Net.Mail.SmtpClient              myMail;
    System.Net.Mail.MailAddressCollection   mailcoll;
    System.Net.Mail.MailAddress             mailFrom;
    System.Net.Mail.MailAddress             mailTo,mailTo2;
    System.Net.Mail.MailAddress             mailCC;
    str                                     receiverMailAddress;
    str                                     mailBody;
    str                                     smtpServer;
    str                                     mailSubject;
    str                                     CcMailAddress;
    int                                     SMTPPort;
    #File
    str                 mail,companynamex;
    userinfo            userInfo;
    str pwd;
    SysEmailParameters parameters = SysEmailParameters::find();
    ;
    new InteropPermission(InteropKind::ClrInterop).assert();

    mailSubject         = subjectx;
    companynamex        = companyinfo::find().Name;
    mailFrom            = new  System.Net.Mail.MailAddress(parameters.SMTPUserName , "AX Server "+companynamex);
    mailTo              = new  System.Net.Mail.MailAddress(sendtomailx,sendtonamex);
    mailCC              = new  System.Net.Mail.MailAddress('mail@gmail.com','mail');
    mailcoll            = new  System.Net.Mail.MailAddressCollection();
    mailBody            = bodyx;

    try
    {
        smtpServer          = SysEmaiLParameters::find(false).SMTPRelayServerName;// using the SMTP server ip         mailMessage         = new System.Net.Mail.MailMessage(mailFrom,mailTo);

        mailmessage.set_Subject(mailSubject);
        mailmessage.set_Body(mailBody);

        SMTPPort            = SysEmaiLParameters::find(false).SMTPPortNumber;
        myMail              = new System.Net.Mail.SmtpClient(smtpServer, SMTPPort);

        //myMail.set_EnableSsl(true); 

        // Untuk SSL enabled seperti: gmail, smtp.gmail.com, port 465 or 587
        myMail.set_EnableSsl(false);

        pwd = SysEmaiLParameters::password();
        mymail.set_Credentials(New System.Net.NetworkCredential(parameters.SMTPUserName, pwd));
        mymail.Send(mailmessage);
    }
    catch(Exception::CLRError)
    {
       throw Exception::CLRError;
    }

    mailMessage.Dispose();
    CodeAccessPermission::revertAssert();

}

Lihat daftar file pada folder

static void Test_ListDirFiles(Args _args)
{
    FilePath        filePath        = 'X:\\DATA\\MyFolder';
    FileNameFilter  fileFilter      = ["*.*", "All files"];

    FileName        fileName;
    int             fileHandle;

    ;

    [fileHandle, fileName] = WinAPI::findFirstFile(strFmt("%1\\%2", filePath, conPeek(fileFilter, 1)));

    while(fileName)
    {
        info(strFmt("%1%2", filePath, fileName));

        fileName = winAPI::findNextFile(fileHandle);
    }
}

Memindahkan file ke folder lain

static void Test_Move_One_File(Args _args)
{
    System.Exception ex;
    Set permSet = new Set(Types::Class);
    str         errorMsg;
    FileName    _srcFile,_destFile;

;
    _srcFile = "c:\\DATA\\Asal\\copy.txt";
    _destFile = "c:\\DATA\\Tujuan\\copy.txt";

    try
    {
        permSet.add(new FileIOPermission(_srcFile, 'rw'));
        permSet.add(new InteropPermission(InteropKind::ClrInterop));
        permSet.add(new FileIOPermission(_destFile, 'rw'));

        CodeAccessPermission::assertMultiple(permSet);

        if(!System.IO.File::Exists(_srcFile))
        {
            Info("Source file not exist !! Proces terminated.");
            Break;
        }
        else
            {
                Info("Source file exist !! File will be moved.");
                if(System.IO.File::Exists(_destFile))
                {
                   System.IO.File::Delete(_destFile);
                }
            }
        System.IO.File::Move(strfmt(@"%1",_srcFile), strfmt(@"%1",_destFile));
        CodeAccessPermission::revertAssert();
    }

    catch (Exception::CLRError)

    {
        ex = ClrInterop::getLastException();
         if (ex != null)
         {
            ex = ex.get_InnerException();
            if (ex != null)
            {
                error(ex.ToString());
            }
        }
    }

    //return true;
}

View Reporting Service SQL Server dari AX 2009

1. Duplicate (copy-paste) form SRSReportView
2. Ganti url pada run(), arahkan pada reporting service sebagai contoh berikut:

public void run()
{
    Microsoft.Dynamics.ReportingServices.ReportSettings settings = reportSettings;
    Microsoft.Dynamics.ReportingServices.ReportException reportException;
    str url;
    str errorMessage;
    int errorCode;
    ;
    super();

    try
    {
        // url = settings.BuildUrl(); --> ganti

           url = http://[server]/Reports/Pages/Report.aspx?ItemPath=/DynamicsAx_AddOn/MyReportService

    ...
    ...
 
    }

3. Buka form nya  dan Tala.....
4. Bisa dilakukan untuk report service yg koneksi langsung ke raw database.