Translate

Sunday, May 3, 2015

SSRS send report as attachment in email using Batch

Hi Folks,

As the standard AX 2012 feature we can schedule any report to send it as attachment on periodic basis. Though standard SysMailerNet class fails if you do not provide any email id in cc. To fix this issue; change the quickSend method of SysMailerNet class as mentioned below:

public void quickSend(str fromAddr, str toAddr, str subject, str body, str cc='', str attachments='')
{

    SysMailerNetAddressField tos;
    SysMailerNetAddressField ccs;
    SysMailerNetAttachments mailAttachments;
    SysEmailParameters parameters;

    List emailAddresses;
    ListEnumerator enum;
    ;

    this.fromAddress(fromAddr);

    tos = this.tos();
    emailAddresses = SysEmailDistributor::splitEmail(toAddr);
    enum = emailAddresses.getEnumerator();
    while(enum.moveNext())
    {
        tos.add(enum.current());
    }

    this.subject(subject);
    this.htmlBody(body);

    //USR-Start
    ccs = this.ccs();
    emailAddresses = SysEmailDistributor::splitEmail(cc);
    enum = emailAddresses.getEnumerator();
    while(enum.moveNext())
    {
        ccs.add(enum.current());
    }

    /*if (!prmisDefault(cc))
    {
        ccs = this.ccs();
        ccs.add(cc);
    }*/
    //USR-End

    if (!prmisDefault(attachments))
    {
        mailAttachments = this.attachments();
        mailAttachments.add(attachments);
    }

    this.priority(System.Net.Mail.MailPriority::Normal);

    parameters = SysEmailParameters::find();

    if (parameters.smtpRelayServerName)
    {
        this.smtpRelayServer(parameters.smtpRelayServerName,parameters.smtpPortNumber,parameters.smtpUserName,SysEmailParameters::password(),parameters.ntlm);
    }

    this.sendMail();

}

How to add Printer lookup in AX 2012

1. Create a class or add below method to use it globally:

Class printers
{

}

//This method loads all available printers to a Map object 
static Map printerMap()
{
    Microsoft.Dynamics.AX.Framework.Reporting.Shared.PrinterHelper printerHelper;
    Microsoft.Dynamics.AX.Framework.Reporting.Shared.PrinterInfo printerInfo;
    System.Collections.ArrayList names;
    System.Collections.IEnumerator enumerator;
    Map         printerMap;

    str name;
    int printerStatus;
    str driverName;
    str portName;
    str comments;
    int jobCountSinceLastReset;

    if(!printerMap)
    {
        printerMap = new Map(Types::String, Types::Container);

        // BP Deviation documented
        printerHelper = new Microsoft.Dynamics.AX.Framework.Reporting.Shared.PrinterHelper();
        names = printerHelper.get_PrinterNames();
        if (names != null)
        {
            enumerator = names.GetEnumerator();
            while (enumerator.MoveNext())
            {
                name = enumerator.get_Current();
                printerInfo = printerHelper.GetPrinterInfo(name);

                // BP Deviation documented
                printerStatus           = CLRInterop::getAnyTypeForObject(printerInfo.get_PrinterStatus());
                // BP Deviation documented
                driverName              = CLRInterop::getAnyTypeForObject(printerInfo.get_DriverName());
                // BP Deviation documented
                portName                = CLRInterop::getAnyTypeForObject(printerInfo.get_PortName());
                // BP Deviation documented
                comments                = CLRInterop::getAnyTypeForObject(printerInfo.get_Comment());
                // BP Deviation documented
                jobCountSinceLastReset  = CLRInterop::getAnyTypeForObject(printerInfo.get_JobCountSinceLastReset());

                printerMap.insert(name, [name, printerStatus, driverName, portName, comments, jobCountSinceLastReset]);
            }
        }
    }

    return printerMap;
}

2. Build lookup Method

public static void printerLookup(FormControl _formControl)
{
    SysTableLookup                  sysTableLookup;
    TmpTableFieldLookup             tmpTableFieldLookup;
    Enumerator                      en;
    List                            entitylist      = new list(types::String);
    Map                             printerMap;
    MapEnumerator                   enumerator;
    PrinterName                     printerName;

    printerMap          = printerMap();//If above method was created in Global class else call specific class 
    enumerator          = printerMap.getEnumerator();
    while (enumerator.moveNext())
    {
        printerName = enumerator.currentValue();
        entitylist.addend(printerName);
    }

    en = entityList.getEnumerator();

    while (en.moveNext())
    {
        tmpTableFieldLookup.TableName = en.current();
        tmpTableFieldLookup.insert();
    }

    sysTableLookup = SysTableLookup::newParameters(tableNum(tmpTableFieldLookup), _formControl);
    sysTableLookup.addLookupfield(fieldNum(TmpTableFieldLookup, TableName));
    sysTableLookup.setLabel("@SYS62708");

    //BP Deviation documented
    sysTableLookup.parmTmpBuffer(tmpTableFieldLookup);
    sysTableLookup.performFormLookup();
}


Get all fields name, type and label of any AOT table or view


Below jobs enables to get list of fields, base data type and label for any particular table.



Output:

Saturday, July 5, 2014

Customer Payment Journal using C#



1.       Verify WSDL URI for AccountsReceivableServices under System administration > Setup > Service and Application Integration Framework > Inbound Ports



2.       Add service reference in .Net project.



3.       Add the below code to create customer payment journal.

private void button1_Click(object sender, EventArgs e)
        {
              //Service declarations
            AccountReceivableServices.CallContext callContext = new AccountReceivableServices.CallContext();
            AccountReceivableServices.CustPaymJournalServiceClient client = new AccountReceivableServices.CustPaymJournalServiceClient();
            AccountReceivableServices.AxdCustPaymJournal paymJournal = new AccountReceivableServices.AxdCustPaymJournal();
            AccountReceivableServices.AxdEntity_LedgerJournalTable1 header = new AccountReceivableServices.AxdEntity_LedgerJournalTable1();
            AccountReceivableServices.AxdEntity_LedgerJournalTrans1 trans = new AccountReceivableServices.AxdEntity_LedgerJournalTrans1();

            callContext.Company = "ceu";
            
              //LedgerJournalTable
            header.JournalName = "Pay";
            header.Name = "AIF test";
            header.JournalType = AccountReceivableServices.AxdEnum_LedgerJournalType.CustPayment;
           
              //LedgerJournalTrans
            trans.AccountType = AccountReceivableServices.AxdEnum_LedgerJournalACType.Cust;
            trans.AccountTypeSpecified = true;
            trans.Company = "ceu";
            var account1 = new AccountReceivableServices.AxdType_MultiTypeAccount() { Account = "11101", DisplayValue = "11101" };
            trans.LedgerDimension = account1;
            trans.AmountCurCredit = 22;
            trans.AmountCurCreditSpecified = true;
            trans.OffsetCompany = "ceu";
            trans.PaymMode = "cash";
            header.LedgerJournalTrans = new AccountReceivableServices.AxdEntity_LedgerJournalTrans1[1] { trans };
            paymJournal.LedgerJournalTable = new AccountReceivableServices.AxdEntity_LedgerJournalTable1 [1] { header };
            try
            {
                client.create(callContext, paymJournal);
            }
            catch (Exception ex)
            {
                string error = ex.Message;
            }

Thursday, March 20, 2014

Developing SSRS Reports for Dynamics AX

300+ copies already sold... Rush now and get one for yourself..!!

***** DEVELOPING SSRS REPORTS FOR DYNAMICS AX *****

Order your copy from:

Amazon.com - http://goo.gl/K94qjr
Amazon.in - http://goo.gl/dMsxnX
Google Books - http://goo.gl/9z0ZTR
Packt Publishing - http://goo.gl/79sUjJ                                                  

Thursday, January 9, 2014

Open Management Reporter from AX 2012 R2

Microsoft Dynamics AX 2012 R2 gives the ability to open Management Reporter directly from AX with various advantages:

  • Easier than ever.
  • Launch Management Reporter direct from Microsoft Dynamics AX 2012 R2.
  • New Management Reporter menu items available under General ledger & Budgeting reports section.
  • Users with permission to Design & Generate reports in MR will be able to see menu item inside AX.
  • Open Report Designer with a click.
  • Connects to the correct server & company based on the AX active session.


Monday, August 12, 2013

Book authored by me - Developing SSRS Reports for Dynamics AX



Developing SSRS Reports for Dynamics AX






Learning everything you always wanted to learn about Microsoft Dynamics AX 2012 Reporting. This book guides you through step-by-step real-world based scenarios using which you could easily learn report development.

What this book covers:

- Building reports using Query.
- Building reports using RDP, Data contract, UI Builder, Controller classes.
- Building Auto-design & Precision design reports.
- Building advanced reports using Visual Studio.
- Building Tablix, Drill through, Chart reports using Visual Studio.
- Managing AX 2012 reports in AOT.
- How deploy AX 2012 reports using various deployment mechanisms.
- How to develop reports from external data source.
- Common reporting expressions (String, Date, Format, Global functions)
- Understanding the usage of common classes & methods used while developing reports.
- Reporting best practices (Report table, Classes, Report design, AOT Queries)



This book is also available now on: