Tuesday, October 4, 2016

Create New Financial Dimension For your customized table in AX 2012 using X++ Code





Lets quickly take a look at how the financial dimensions framework has been redesigned in AX 2012. The following picture show the table design:

Untitled
To add a new financial dimension for your custom table, perform the following steps:
1. Drag the EDT (AOT >> Data Dictionary >> Extended Data Types >> DimensionDefault) to the fields of your table
2. Create a new “Normal” relation on your table linking the newly added “DefaultDimension” field to the “RecId” field of DimensionAttributeValueSet table
Untitled
3. Now create a view for your table. Take care of the following conventions:
  • View should be named exactly DimAttributeYourTable
  • Add your table to DimAttributeYourTable >> Metadata >> Data Sources node
  • This data source should be named exactly BackingEntity
  • Add the following three fields naming them exactly as mentioned
    • Key – Use surrogate key field e.g. RecId
    • Value – Use natural key field e.g TrackingNum
    • Name – Use any descriptive field e.g. DeliveryName
Untitled
4. Create and run the following  job to clear the dimension cache:
static void clearCache(Args _args)
{
    DimensionCache::clearAllScopes();
    info("done");
}
5. Now open General Ledger >> Setup >> Financial dimensions >> Financial dimensions
6. Create a new financial dimension
7. Select your newly added dimension from the “Use values from” lookup:
Untitled

Now if you want to add this financial dimension to any of the existing chart of accounts, perform the following steps:
1. Open General Ledger >> Setup >> Chart of accounts >> Configure account structures
2. Select any of the active account structures e.g. “Account Structure P&L (Active)”
3. Click Edit button
4. Click Add segment button
5. Select the newly added dimension
6. Finally activate the dimension to let the changes take effect.
Untitled


Friday, January 8, 2016

Export all projects from a specified Layer



Export all projects  from a specified Layer

We want to take the projects backup on different layers.  This is a good way to backup your projects and/or their definitions.

static void mahiExportProjects(Args _args)
{
    #AotExport
    TreeNodeIterator        tni;
    ProjectNode             projectNode;
    int                     exportFlag;
    Dialog                  dialog = new Dialog();
    DialogField             folderName;
    DialogField             projectDefinitionOnly;
    DialogField             exportFromLayer;
    DialogField             projectType;
    UtilEntryLevel          layer;

    dialog.addText("Export all projects from selected Layer");
    projectType             = dialog.addFieldValue(enumStr(ProjectSharedPrivate), ProjectSharedPrivate::ProjPrivate);
    projectDefinitionOnly   = dialog.addField(extendedTypeStr(NoYesId), 'Definition Only','It will import only def of the projects');
    folderName              = dialog.addField(extendedTypeStr(FilePath));
    exportFromLayer         = dialog.addField(enumStr(UtilEntryLevel), 'Layer');

    dialog.run();

    if (dialog.closedOk())
    {
        if (!folderName.value())
            throw error("Folder must be select");

        exportFlag = #export;
        if (projectDefinitionOnly.value())
            exportFlag += #expProjectOnly;

        layer = exportFromLayer.value();

        switch (projectType.value())
        {
            case ProjectSharedPrivate::ProjPrivate:
                tni = SysTreeNode::getPrivateProject().AOTiterator();
                break;

            case ProjectSharedPrivate::ProjShared:
                tni = SysTreeNode::getSharedProject().AOTiterator();
                break;

        }

        projectNode = tni.next() as ProjectNode;

        while (projectNode)
        {
            if (projectNode.AOTLayer() == layer)
            {
                projectNode.treeNodeExport(folderName.value() + '\\' + projectNode.name() + '.xpo', exportFlag);
            }

            projectNode = tni.next() as ProjectNode;
        }
    }
    else
        warning("Cancelled by User");
}

Monday, December 28, 2015

AX 2012 SSRS Report Development - Part 2


SSRS report in Visual studio
Open Visual Studio, click on File -> New Project. New Project dialog is open as shown below:

Now let us add a new report to the newly created report Model as shown below. Right click on the Project from the solution explorer, Add >> Report
Give the Proper Name to the Report and these are the following nodes.
The purpose of each report Node is described below:

Ø  Datasets: The report dataset retrieves data from the AX, We can retrieve the data from the following ways.
Create new data set and go to Properties
§  Query                            
     Data get from AX Query
§  Business Logic                          
     Data get from C# Business Logic
§  Report data provider (RDP).       
    Data get from AX Tmp Tables through DP Classes
§  AX Enum Provider



Ø  Designs: The design or layout of the report on which the data would be displayed after retrieving from AX. There are two types of report designs available in SSRS report ,There are two types of report designs available in SSRS report
§   Auto Design:        It will automatically set design for the Dataset.
§  Precision Design.  we will use for a custom placement of fields in a report and complex report designs.

Ø  Images: Any embedded images that you want to display on SSRS report.

Ø  Data Methods: Business logic written in C#. Data methods are useful to Link Action to open the AX Form.

Ø  Parameters: Report parameters which are to be displayed on SSRS report and user can filter the report based on those parameters.

Friday, February 15, 2013

Creating Payment Journal from Text file through X++ in AX 2012



static void Amundla_GLPosting(Args _args)
{
    Ledgerjournalname       ledgerjournalname;
    LedgerjournalTable      LedgerjournalTable;
    LedgerjournalTrans      LedgerjournalTrans;
    LedgerjournalCheckPost  LedgerjournalCheckPost;
    NumberSeq               numberSeq;
    Container               con;
    Filename                filename, Filename2;
    FileIOPermission        permission;
    TextIO                  textIO, textIO1;
    Dialog                  dialog;
    DialogField             dialogField;
 
    #File

   ;

   dialog = new Dialog("Posting Payment Journal");
   dialogField = dialog.addField(ExtendedTypeStr("FilenameOpen"),"Source file");

   if (dialog.run())
   {
        Filename = dialogField.value();
        permission = new fileIOpermission(filename,"RW");
        permission.assert();
        textIO = new TextIO(filename,#io_read);
        textIO.inFieldDelimiter('|');

        select ledgerjournalname where ledgerjournalname.JournalName == "ICICI BR";
        ttsBegin;
        LedgerjournalTable.JournalName      =   ledgerjournalname.JournalName;
        LedgerjournalTable.initFromLedgerJournalName();
        LedgerjournalTable.JournalNum       =   JournalTableData::newTable(LedgerjournalTable).nextJournalId();
        LedgerjournalTable.insert();
        ttsCommit;

       if(textIO)

       {

         while(textIO.status() == IO_Status::Ok)

           {
               con = textIO.read();
               if(con)
               {


                    ttsBegin;
                    numberSeq                               =   NumberSeq::newGetVoucherFromId((ledgerjournalname.NumberSequenceTable));
                    LedgerjournalTrans.Voucher              =   numberSeq.voucher();
                    LedgerjournalTrans.JournalNum           =   LedgerjournalTable.JournalNum;
                    LedgerjournalTrans.CurrencyCode         =   "USD";
                    LedgerjournalTrans.ExchRate             =   Currency::exchRate(LedgerjournalTrans.CurrencyCode);
                    LedgerjournalTrans.AccountType          =   LedgerJournalACType::Cust;
                    LedgerjournalTrans.parmAccount(conPeek(con,2),LedgerjournalTrans.AccountType);
                    LedgerjournalTrans.Txt                  =   conPeek(con,1);
                    LedgerjournalTrans.AmountCurCredit      =   conPeek(con,3);
                    LedgerjournalTrans.TransDate            =   str2Date(conPeek(con,4),123);
                    LedgerjournalTrans.OffsetAccountType    =   LedgerjournalTable.OffsetAccountType;
                    LedgerjournalTrans.OffsetLedgerDimension=   LedgerjournalTable.OffsetLedgerDimension;
                    LedgerjournalTrans.DefaultDimension     =   CustTable::find(conPeek(con,2)).DefaultDimension;
                    LedgerjournalTrans.OffsetDefaultDimension=  CustTable::find(conPeek(con,2)).DefaultDimension;
                    LedgerjournalTrans.insert();
                    ttsCommit;


               }
           }
                    LedgerjournalCheckPost      =   LedgerjournalCheckPost::newLedgerJournalTable(LedgerjournalTable,NoYes::Yes);
                    LedgerjournalCheckPost.run();

     
       }
   }
}