Friday, January 10, 2014

Print PDF files from AX X++ code

Print External 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); 
    }
}



Iace Technologies & Services....!!!

Join Two Tables at Run Time


static void theAxapta_JoinTables(Args _args)
{
    Query                     query;
    QueryBuildDataSource      queryBuildDataSource1,
                              queryBuildDataSource2;
    QueryBuildRange           queryBuildRange;
    QueryBuildLink            queryBuildLink;
    ;
    // Create a new query object
    query = new Query();
    // Add the first data source to the query
    queryBuildDataSource1 = query.addDataSource(tablenum(CarTable));
    // Add the range to this first data source
    queryBuildRange = queryBuildDataSource1.addRange(fieldnum(CarTable, ModelYear));
    // Add the second datasource to the first data source
    queryBuildDataSource2 =   queryBuildDataSource1.addDataSource(tablen
    um(RentalTable));
    // Add the link from the child data source to the 
    //parent data 
    source
    queryBuildLink = queryBuildDataSource2.addLink(fieldnum(CarTable, 
    CarId),fieldnum(RentalTable, CarId));
}


Note:
This process (query through X++ code) is very similar to create a query directly through AOT node.
AOT -> Query -> Right Click -> New Query
I would suggest first create a query through query node, than go for this code.


This posting is provided "Iace Technologies & Services"...!!!

How to use Complex Query Ranges in Dynamics AX


Adding a query with athe Datasource to query.

query = new Query();
dsInventTable = query.addDataSource(tableNum(InventTable));
// Add our range
queryBuildRange = dsInventTable.addRange(fieldNum(InventTable, DataAreaId));

Simple criteria

Lets find the record where the value of ItemId field is Item1. Take note of the single quotes and parenthesis surrounding the entire expression.

queryBuildRange.value(strFmt('(ItemId == "%1")', queryValue("Item1")));
Find records where the ItemType is Service. Note the use of any2int().
queryBuildRange.value(strFmt('(ItemType == %1)', any2int(ItemType::Service)));

Find records where the ItemType is Service or the ItemId is Item1. Note the nesting of the parenthesis in this example.

queryBuildRange.value(strFmt('((ItemType == %1) || (ItemId == "%2"))', any2int(ItemType::Service), queryValue("Item1")));

Find records where the modified date is after 1st January 2000. Note the use of Date2StrXpp() to format the date correctly.

queryBuildRange.value(strFmt('(ModifiedDate > %1)', Date2StrXpp(01012000)));

Complex criteria with combined AND and OR clauses

We need to find those records where the ItemType is Service, or both the ItemType is Item and the ProjCategoryId is Spares. This is not possible to achieve using the standard QueryRange syntax.

queryBuildRange.value(strFmt('((%1 == %2) || ((%1 == %3) && (%4 == "%5")))',fieldStr(InventTable, ItemType),any2int(ItemType::Service),any2int(ItemType::Item),fieldStr(InventTable, ProjCategoryId),queryValue("Spares")));



This posting is provided "Iace Technologies & Services"...!!!

AX2012 R2 RunAs and Global::RunClassMethodIL

Just a quick note on using RunAs in AX2012: The static method being called by RunAs should have a container parameter in the method declaration. Otherwise, system will complain that the static method was not found. So:
?
// This would fail with static method not found error.
public static void methodWithoutParm()
{
}
// This would work!
public static void methodWithContainerParm(container _c)
{
}
In fact, the same can be said to Global::RunClassMethodIL. However, the error throw by Global::RunClassMethodIL is more helpful. It'll complain that the parameter passed into the static method is incorrect. Seeing that a third parameter of type container is mandatory for Global::RunClassMethodIL, it's easier to get the idea to try adding the container parameter in the target static method. =]


This posting is provided "Iace Technologies & Services" .

Thursday, January 9, 2014

Installing Ax 2009


Installing Microsoft Dynamics AX 2009 requires more than the installation DVD. This post will provide you with an overview of the software components and their download sources to get you better prepared for the installation.
Following Components are required to install Ax 2009
  • Microsoft Dynamics AX 2009 Release DVD ISO which You may download from download the Microsoft Dynamics 2009 Release May Edition DVD ISO file (1.7 GB in size) from PartnerSource Since it is in ISO format, you may use any Virtual DVD software to mount it as a DVD disc to use it directly or to extract the files to a physical location.

  • Microsoft .NET Framework 3.5 Microsoft Dynamics AX 2009 utilized the latest features from Windows Presentation Foundation, etc. You need to install Microsoft .NET Framework 3.5 before you are able to install Microsoft Dynamics AX 2009. The table bellow shows the options you have to get the .NET Framework 3.5 installed. Pick one that suits your need best
  • Service Pack 2 for Microsoft SQL Server 2005 If you are hosting your Dynamics AX 2009 data with Microsoft SQL Server 2005, you will need Service Pack 2 or later. This service pack has been released for over a year. In case you have not updated your Microsoft SQL Server 2005 to SP2, you may download the update at Microsoft Download: SQL Server 2005 SP2.

  • Dynamics AX 2009 Demo Data Microsoft has not realeased any official demo data for Dynamics AX 2009 Release yet. but you can download and use Demo data AX 2009 CTP3 VPC Ver02

  • Microsoft Windows Sharepoint Services 3.0 with Service Pack 1 Sharepoint Services 3.0 SP1 is required to host the Role Centers and Enterprise Portal. It is not included in the Dynamics AX 2009 Installation DVD. You have an option to use Microsoft Office Sharepoint Server 2007 or Microsoft Windows Sharepoint Services 3.0. It is available for download at Microsoft Download. Windows SharePoint Services 3.0 with Service Pack 1

  • Microsoft Visual Studio 2008 Shell (isolated mode) Redistributable PackageThis package is required for the Reporting Extension to work. There are two Microsoft Visual Studio 2008 Shell redistributable package; isolated and integrated. Make sure you are having the isolated package. When you install this package, please note that the executable Microsoft Visual Studio 2008 Shell (isolated mode) Redistributable Package



Iace Technologies & Services...!!

5 Productivity tips for SSRS development in Dynamics AX 2012



Here is 5 Productivity tips that can help you develop SSRS reports faster in Dynamics AX 2012.






















Iace Technologies & Services.....!!!!

SSRS Tip: Take care to clear the temp table record in RDP reports




All RDP reports adopt the approach of filling in all the required data into a temp table. In this article let us how a simple “clear” statement could be helpful as well as give way to a hidden problem in disguise.

Consciously make use of “table.clear()”
Let us look at the example here where the method highlighted here “insertCustListTmp” is called in a loop from the procesreport method.The method “isReversed” whose implementation is not shown here finds if there is reverse happened for the trans and also returns the reverse journal id. (Don’t funtionally interpret the implementation)

CODE :
private void insertCustTransListTmp(ExchAdjustment _exchangeAdjustmentType,
CustTransListTmp _custTransListTmp,
RecordInsertList _tmpTableRecordList,
TransactionReversalTrans _transactionReversalTransLocal)
{  
    //_custTransListTmp.clear();
    this.initBalance(_exchangeAdjustmentType, _custTransListTmp);
    _custTransListTmp.TraceNum = _transactionReversalTransLocal.TraceNum;
    if (this.isReversed())
    {
        _custTransListTmp.Reversed       = true;
        _custTransListTmp.ReverseVoucher = this.getReversedVoucer();
    }
   _custTransListTmp.Reversed = this.reversed(_transactionReversalTransLocal);
   _custTransListTmp.AccountNum = custTable.AccountNum;
   _custTransListTmp.Name = custTable.name();

   _custTransListTmp.Voucher = custTrans.Voucher;
_custTransListTmp.insert();
}

Following is the data present at the table level.











when you run your report it could appear that something is going terribly wrong in your logic but it could be the simple clear statement missing at the back.

Practically though the common problem area could be in reports this can happen anywhere both in temp and regular tables. However you can also use this to your advantage when say every field is initialized unlike the conditional flows specified here. So you can have the methods like “initFromCustTable” called only once and doesn’t required to be call again since the clear is not invoked. Whatever is the case make sure the decision is taken consciously.

Optionally run this code to quickly understand what is discussed here…


static void JobTestClear(Args _args)


{
    CustTransListTmp transTmp;
    CustTable        custTable;
    boolean insert;   

    select * from custTable;   
while (custTable)
{
        if (insert)
         {
transTmp.AccountNum = custTable.AccountNum;
         }     
        transTmp.insert();         
        insert = !insert;         
        print transTmp.AccountNum;
        pause;         
        next custTable;

    }


Iace Technologies & Services…!!!