January 12, 2013

How to pass values from form to report

How to pass values from form to report

Hi Folks,

Follow below steps to understand this, 

1. Make the report as Interactive

image

2. Create Method initFromCaller and pass the args to it.     

image

3. Set the report caption (it will appear in dialog).  

image

4. The Method initFromCaller.
Method initFromCaller  Basicllt this form will call whenever you call this menu item from FORM. 

public void initFromCaller(Args _args)
{
InventJournalTable inventJournalTable;
QueryBuildDataSource qbds;
;
if (_args.caller())
{
if (! _args.record().recId)
   throw error(strfmt("@SYS22338",funcname()));
switch (_args.dataset())
{
case tablenum(InventJournalTable):

inventJournalTable = _args.record();
if (inventJournalTable.journalType != InventJournalType::Transfer)
throw error(strfmt("@SYS23396",funcname()));

break;
default:
throw error(strfmt("@SYS23396",funcname()));
}
}

if (true || inventJournalTable.journalId)
{
qbds = element.query().dataSourceTable(tablenum(InventJournalTrans));
SysQuery::findOrCreateRange(qbds, fieldnum(InventJournalTrans, journalId)).value(inventJournalTable.journalId);
SysQuery::findOrCreateRange(qbds, fieldnum(InventJournalTrans, journalType)).value(queryValue(InventJournalType::Transfer));
}
}

Enjoy Guys......

-Harry


January 09, 2013

Sending mail from AX using .NET Framework

Sending mail from AX using .NET Framework

Sometimes happen that SysMailer class (using CDO) is not the right solution for sending mails with attachments. There is a little sample of X++ Job that is using System.Net.Mail namespace to achieve same.


static void JobNETSendMail(Args _args)
{
    System.Net.Mail.MailMessage             mailMessage;
    System.Net.Mail.Attachment              attachment;
    System.Net.Mail.AttachmentCollection    attachementCollection;
    System.Net.Mail.SmtpClient              smtpClient;
    System.Net.Mail.MailAddress             mailAddressFrom;
    System.Net.Mail.MailAddress             mailAddressTo;
    str                                     strBody;
    str                                     strSMTPServer;
    str                                     strFileName;
    FileIOPermission                        perm;
    ;

    // preparing parameters
    mailAddressFrom = new System.Net.Mail.MailAddres"test@localmail.com", "");
    mailAddressTo = new  System.Net.Mail.MailAddress("admin@localmail.com","");
    strBody = "There is a email body";
    strSMTPServer = "MailServerName";
    
    // preparing mail with body, subject, from, to.
    mailMessage = new System.Net.Mail.MailMessage(mailAddressFrom, mailAddressTo);
    mailmessage.set_Subject("There is a email subject");
    mailmessage.set_Body(strBody);
    attachementCollection = mailMessage.get_Attachments();

    strFileName = "C:\\path\\filename";
    // assert permision
    perm = new FileIOPermission(strFileName,'w');
    perm.assert();

    // attaching file to that email.
    attachment = new System.Net.Mail.Attachment(strFileName);
    attachementCollection.Add(attachment);
    smtpClient = new System.Net.Mail.SmtpClient(strSMTPServer);
    smtpClient.Send(mailmessage);
    
    // release permision
    CodeAccessPermission::revertAssert();
}

-Harry