Sunday, March 23, 2014

Importing Fixed Asset Value Model in AX 2012 using X++

static void FixedAssetValueModelUpload(Args _args)
{

    SysExcelApplication             application;
    SysExcelWorkbooks               workbooks;
    SysExcelWorkbook                workbook;
    SysExcelWorksheets              worksheets;
    SysExcelWorksheet               worksheet;
    SysExcelCells                   cells;
    COMVariantType                  type;

    FilenameOpen                    filename;
    dialogField                     dialogFilename;

    Dialog                          dialog;

    itemId                          itemId;
    Dialog                          d;
    DialogField                     df1;
    CommaTextIo                     file;
    container                       rec;
    BudgetTransactionHeader         BudgetTransactionHeader;
    BudgetTransactionLine           BudgetTransactionLine;
    ledgerAccountContract           ledgerAccountContract;
    assetBook                       assetBook;
    PurchTable                      purchTable;


    int                             i,num,coun,lineCount = 1;
    Integer                         row = 1;
    str                             ledgerAcc,departmentval,event,service,phase,department;
    AssetTable                      assetTable;
    NumberSeq assetIdNumberSeq;
    NumberSequenceTable numberSequenceTable;
    NumberSequenceReference numberSequenceReference;
    Struct                      struct;

    DimensionDefault            DimensionDefault;
     container   ledgerDimension;
    //int i;


    //(PYLVacation).VacationTransId



    str COMVariant2Str(COMVariant _cv,int _decimals = 0, int _characters = 0, int _separator1 = 0, int _separator2 = 0)
    {
        switch (_cv.variantType())
        {
            case (COMVariantType::VT_BSTR):
                return _cv.bStr();

            case (COMVariantType::VT_R8):
                return num2str(_cv.double(),_characters,_decimals,_separator1,_separator2);

            case (COMVariantType::VT_DATE):
                return date2str(_cv.date(),123,2,1,2,1,4);

            case (COMVariantType::VT_EMPTY):
                return '';

            default:
                throw error(strfmt("@SYS26908", _cv.variantType()));
        }
    }
   ;

    dialog              =   new Dialog('Budget Upload');
    dialogFilename      =   dialog.addField(ExtendedTypeStr("FilenameOpen"));

    dialog.filenameLookupTitle('Import from excel.');
    dialog.caption('Import From Excel');
    //dialog.addText("This is to import General Journal Account Entry records directly\n");
    //dialog.addText("Following are mandatory in the display value :\n1. MainAccount\n2. LineOfBusiness Dimension\n3. Investment Dimension\n4. Department dimension is optional").displayHeight(6);
    //dialog.addText("Template order:\n");
    //dialog.addText(strFmt("%1\n%2\n%3\n%4\n","DisplayValue","AccountingCurrencyAmount","GeneralJournalEntryRecid","Currency Code - Hardcoded here")).displayHeight(15);

    dialogFilename.value(filename);

    if(dialog.run())
    {
        filename            =   dialogFilename.value();

        application         =   SysExcelApplication::construct();
        workbooks           =   application.workbooks();

        try
        {
            workbooks.open(filename);
        }
        catch (Exception::Error)
        {
            throw error('File cannot be opened.');
        }

        workbook            =   workbooks.item(1);
        worksheets          =   workbook.worksheets();
        worksheet           =   worksheets.itemFromNum(1);
        cells               =   worksheet.cells();

        try
        {
            ttsbegin;
            do
            {
                row++;
                type = cells.item(row+1, 1).value().variantType();
                //ledgerAcc = (COMVariant2Str(cells.item(row, 5).value()));
                //departmentval = (COMVariant2Str(cells.item(row, 6).value()));
                //service  = (COMVariant2Str(cells.item(row, 7).value()));
                //event = (COMVariant2Str(cells.item(row, 8).value()));
                assetIdNumberSeq = assetTable.initAssetNumberSeq((COMVariant2Str(cells.item(row, 1).value())));

                if (assetIdNumberSeq)
                {

                assetTable.AssetId = assetIdNumberSeq.num();
                assetIdNumberSeq.used();

                }

                assetTable.AssetGroup = (COMVariant2Str(cells.item(row, 1).value()));
                assetTable.Name = (COMVariant2Str(cells.item(row, 3).value()));
                assetTable.NameAlias = (COMVariant2Str(cells.item(row, 3).value()));
                assetTable.AssetType = AssetType::Tangible;
                assetTable.PropertyType = AssetPropertyType::FixedAsset;
                assetTable.Quantity = 1;//((cells.item(row, 8).value().double()));
                assetTable.UnitOfMeasure = "PIECE";//(COMVariant2Str(cells.item(row, 8).value()));
                assetTable.UnitCost = ((cells.item(row, 5).value().double()));
                //assetTable.Location = (COMVariant2Str(cells.item(row, 8).value()));
                assettable.insert();


                //assetid = conPeek(readCon,1);
                //bookid = conPeek(readCon,2);
                assetBook.clear();

                assetBook = AssetBook::find(assetTable.AssetId,"ALL",true);
                select forUpdate assetBook where assetBook.AssetId == assetTable.AssetId;

                if(!assetBook)
                {
                    info(strFmt("%1",assetTable.AssetId));
                    continue;
                }
                assetBook.AssetGroup = (COMVariant2Str(cells.item(row, 1).value()));
                assetBook.Status = AssetStatus::NoAcquisition;
                department = (COMVariant2Str(cells.item(row, 6).value()));
                Event= (COMVariant2Str(cells.item(row, 7).value()));
                Service = (COMVariant2Str(cells.item(row, 8).value()));
                phase = (COMVariant2Str(cells.item(row, 9).value()));

                struct = new Struct();
                struct.add('Department',(COMVariant2Str(cells.item(row, 6).value())));
                struct.add('Event', (COMVariant2Str(cells.item(row, 7).value())));
                struct.add('Phase', (COMVariant2Str(cells.item(row, 8).value())));
                struct.add('Service', (COMVariant2Str(cells.item(row, 9).value())));

                ledgerDimension = conNull();
                ledgerDimension += struct.fields();

                for (i = 1; i <= struct.fields(); i++)
                {
                    ledgerDimension += struct.fieldName(i);
                    ledgerDimension += struct.valueIndex(i);
                }

                DimensionDefault = AxdDimensionUtil::getDimensionAttributeValueSetId(ledgerDimension);
                assetBook.DefaultDimension = DimensionDefault;
                assetBook.PostingProfile        = "FA";//Confirm for other companies
                assetBook.Depreciation          = NoYes::Yes;

                //assetBook.LifeTime              = conPeek(readCon,12);
                //assetBook.DepreciationStartDate = str2Date(conPeek(readCon,13),213);

                assetBook.AcquisitionPrice      = (cells.item(row, 5).value().double());
                assetBook.AcquisitionDate       =  str2date(COMVariant2Str(cells.item(row, 4).value()),123);
                //assetBook.UsedFromDate          =  str2Date(conPeek(readCon,17),213);
                //assetBook.ServiceLife           = conPeek(readCon,18);
                PurchTable  = PurchTable::find((COMVariant2Str(cells.item(row, 13).value())));
                assetBook.PurchId = (COMVariant2Str(cells.item(row, 13).value()));
                assetBook.VendAccount           = PurchTable.OrderAccount;
                assetBook.VendInvoiceId  = COMVariant2Str(cells.item(row, 11).value());
                assetBook.update();

                num++;
                info(strFmt("%1^%2^%3^%4^%5^%6^%7^%8^%9^%10^%11^%12^%13^%14^%15",num,assetBook.AssetId,assetTable.Name,assetTable.Quantity,assetTable.UnitCost,assetTable.UnitOfMeasure,department,event,phase,service,
                assetBook.AcquisitionPrice,assetBook.AcquisitionDate,assetBook.PurchId,assetBook.VendAccount,assetBook.VendInvoiceId));

                coun++;
                print(coun);


            } // do

          // info(strFmt(" %1 Records Updated", num));

            while (type != COMVariantType::VT_EMPTY);
                    info(strFmt("No of records updated - %1",num));
            ttscommit;
            application.quit();
        }// try
        catch
        {
            throw error('Error in Update.');
        }
    }
    pause;
}

Importing Product Master into AX 2012 using X++ job

static void UploadProductMaster(Args _args)
{
    CommaTextIO         csvFile;
    container                  readCon;
    counter                     icount,inserted;
    Dialog                      dialog;
    DialogField             dfFileName;
    FileName                 fileName;

    InventTable                            inventTable;
    EcoResProduct                      ecoResProduct;
    EcoResProductMaster          EcoResProductMaster;
    EcoResProductTranslation  ecoResProductTranslation;    
    InventModelGroupItem        InventModelGroupItemLoc;
    
    EcoResDistinctProductVariant                    EcoResDistinctProductVariant;   
    EcoResProductDimensionGroupProduct  ecoResProductDimensionGroupProduct;
    EcoResStorageDimensionGroupItem         ecoResStorageDimensionGroupItem;
    EcoResTrackingDimensionGroupItem       ecoResTrackingDimensionGroupItem;
    EcoResStorageDimensionGroupProduct   ecoResStorageDimensionGroupProduct;
    EcoResTrackingDimensionGroupProduct ecoResTrackingDimensionGroupProduct;
    
    InventTableModule           inventTableModule;
    inventItemGroupItem         inventItemGroupItem;
    InventItemSetupSupplyType   inventItemSetupSupplyType;
    ecoResProductIdentifier     ecoResProductIdentifier;
    

    ItemId                      itemID ;
    str       name,Description,itemtype,productDimensionGroup,StorageDimensionGroup,TrackingDimensiongroup,modelGroupId,itemGroupId,unit,price,searchname;
    
    inserted =0;
    #File


    dialog = new Dialog("Pick the file");
    dfFileName = dialog.addField(extendedTypeStr("FilenameOpen"));
    dialog.filenameLookupFilter(["All files", #AllFiles]);


    if (dialog.run())
    {
        csvFile = new CommaTextIo(dfFileName.value(), 'r');
        csvFile.inFieldDelimiter(',');
        readCon = csvFile.read();
        ttsBegin;
        while(csvFile.status() == IO_Status::OK)
        {
            readCon = csvFile.read();

            if(readCon)
            {
                icount++;

                itemId                = "ABC9";//conPeek(readCon,1); 
                name                  = "ABC9name";//conPeek(readCon,2);
                searchname      = "searchname";
                Description      = "DEscription";
                itemtype            = "BOM";
                productDimensionGroup   = "PG_4";//conPeek(readCon,3);
                StorageDimensionGroup   = "PDG_001";//conPeek(readCon,4);
                TrackingDimensiongroup  = "PDG_001";//conPeek(readCon,5);
                modelGroupId    = "FIFO";//conPeek(readCon,6);
                itemGroupId     = "Television";//conPeek(readCon,7);
                unit            = "ea";//conPeek(readCon,8);
                price           = "0";//conPeek(readCon,9);
                
                 select firstOnly ecoResProduct where EcoResProduct.DisplayProductNumber == itemId; 

                if(!ecoResProduct)
                {
                    EcoResProductMaster.initValue();
                    EcoResProductMaster.DisplayProductNumber = itemId;
                    EcoResProductMaster.SearchName = searchname;
                    EcoResProductMaster.ProductType = EcoResProductType::Item;
                    EcoResProductMaster.VariantConfigurationTechnology = EcoResVariantConfigurationTechnologyType::PredefinedVariants;
                    EcoResProductMaster.insert();
                    ecoResProduct= EcoResProductMaster;
                }

                ecoResProductTranslation.Product = ecoResProduct.RecId;
                ecoResProductTranslation.Name = name;
                EcoResProductTranslation.Description = Description;
                ecoResProductTranslation.setDefaultLanguage();
                ecoResProductTranslation.insert();

                EcoResDistinctProductVariant.DisplayProductNumber = itemId ;
                EcoResDistinctProductVariant.ProductMaster = ecoResProduct.RecId;
                EcoResDistinctProductVariant.ProductType = ecoResProduct.ProductType;
                EcoResDistinctProductVariant.insert();

                inventTable.initValue();
                inventTable.initFromEcoResProduct(ecoResProduct);
                inventTable.ItemId = itemId;
                inventTable.NameAlias = ecoResProduct.SearchName;
                if(ItemType == "BOM")
                    inventTable.PmfProductType = PmfProductType::BOM;
                else
                    inventTable.PmfProductType = PmfProductType::None;
                inventTable.insert(true);

                inventTableModule.initValue();
                inventTableModule.ItemId = inventTable.ItemId;
                inventTableModule.ModuleType = ModuleInventPurchSales::Invent;
                InventTableModule.UnitId = unit;
                InventTableModule.Price = any2real(Price);
                inventTableModule.insert();

                inventTableModule.initValue();
                inventTableModule.ItemId = inventTable.ItemId;
                inventTableModule.ModuleType = ModuleInventPurchSales::Purch;
                InventTableModule.UnitId = unit;
                InventTableModule.Price =  any2real(Price);
                inventTableModule.insert();

                inventTableModule.initValue();
                inventTableModule.ItemId = inventTable.ItemId;
                inventTableModule.ModuleType = ModuleInventPurchSales::Sales;
                InventTableModule.UnitId = unit;
                InventTableModule.Price = any2real(Price);
                inventTableModule.insert();

                //Create inventItemLocation
                InventItemLocation::createDefault(inventTable.ItemId);

                // Creates a new item default order type for the product that is released.

                inventItemSetupSupplyType.initValue();
                inventItemSetupSupplyType.ItemId = inventTable.ItemId;
                inventItemSetupSupplyType.ItemDataAreaId = inventTable.DataAreaId;
                inventItemSetupSupplyType.insert();

                //create relationship tables to dimension groups.

                ecoResStorageDimensionGroupProduct = EcoResStorageDimensionGroupProduct::findByProduct(ecoResProduct.RecId);
                ecoResTrackingDimensionGroupProduct = EcoResTrackingDimensionGroupProduct::findByProduct(ecoResProduct.RecId);

                if (ecoResStorageDimensionGroupProduct.RecId)
                {
                    // mandatory storage dimension group for the product
                    ecoResStorageDimensionGroupItem.ItemDataAreaId = inventTable.DataAreaId;
                    ecoResStorageDimensionGroupItem.ItemId = inventTable.ItemId;
                    ecoResStorageDimensionGroupItem.StorageDimensionGroup = ecoResStorageDimensionGroupProduct.StorageDimensionGroup;
                    ecoResStorageDimensionGroupItem.insert();
                }

                if (ecoResTrackingDimensionGroupProduct.RecId)
                {
                    // mandatory tracking dimension group for the product
                    ecoResTrackingDimensionGroupItem.ItemDataAreaId = inventTable.DataAreaId;
                    ecoResTrackingDimensionGroupItem.ItemId = inventTable.ItemId;
                    ecoResTrackingDimensionGroupItem.TrackingDimensionGroup = ecoResTrackingDimensionGroupProduct.TrackingDimensionGroup;
                    ecoResTrackingDimensionGroupItem.insert();
                }


                InventModelGroupItemLoc.ItemDataAreaId = inventTable.dataAreaId;
                InventModelGroupItemLoc.ItemId = inventTable.ItemId;
                InventModelGroupItemLoc.ModelGroupId =modelGroupId;
                InventModelGroupItemLoc.ModelGroupDataAreaId = curext();
                InventModelGroupItemLoc.initValue();
                InventModelGroupItemLoc.insert();

                 //Item group
                inventItemGroupItem.clear();
                inventItemGroupItem.initValue();
                inventItemGroupItem.ItemDataAreaId = inventTable.dataAreaId;
                inventItemGroupItem.ItemId = inventTable.ItemId;
                inventItemGroupItem.ItemGroupId = itemGroupId;
                inventItemGroupItem.ItemGroupDataAreaId = curext();
                inventItemGroupItem.insert();

                //write product to dimension group relation
                ecoResProductDimensionGroupProduct.initFromProduct(ecoResProduct);
                ecoResProductDimensionGroupProduct.ProductDimensionGroup = EcoResProductDimensionGroup::findByDimensionGroupName(productDimensionGroup).RecId;// "PG_4";
                ecoResProductDimensionGroupProduct.insert();

                ecoResStorageDimensionGroupItem.initValue();
                ecoResStorageDimensionGroupItem.ItemDataAreaId = inventTable.dataAreaId;
                ecoResStorageDimensionGroupItem.ItemId = inventTable.ItemId;
                ecoResStorageDimensionGroupItem.StorageDimensionGroup = EcoResStorageDimensionGroup::findByDimensionGroupName(StorageDimensionGroup).RecId;
                ecoResStorageDimensionGroupItem.insert();

                ecoResTrackingDimensionGroupItem.initValue();
                ecoResTrackingDimensionGroupItem.ItemDataAreaId = inventTable.dataAreaId;
                ecoResTrackingDimensionGroupItem.ItemId = inventTable.ItemId;
                ecoResTrackingDimensionGroupItem.TrackingDimensionGroup = EcoResTrackingDimensionGroup::findByDimensionGroupName(TrackingDimensiongroup).RecId;
                ecoResTrackingDimensionGroupItem.insert();
                
                ecoResProductIdentifier.clear();
                ecoResProductIdentifier.initValue();
                ecoResProductIdentifier.ProductNumber = itemId;
                ecoResProductIdentifier.Product = EcoResProductMaster.RecId; //ecoResProductMaster.RecId;
                ecoResProductIdentifier.insert();
                
            }

        }
        ttsCommit;
    }

}

Reading Data through SQL Data Reader from AX 2012

static void ReadfromSQL(Args _args)//Read Data from SQL
{
    System.Data.SqlClient.SqlConnection      conn;
    System.Data.SqlClient.SqlCommand        cmd;
    System.Data.SqlClient.SqlDataAdapter   da;
    System.Data.SqlClient.SqlDataReader     dr;
    System.Exception                                         netExcepn;
   
    str               Empl;
    TransDate transDate;
    str               strQry;
   
    try
    {
        conn = new System.Data.SqlClient.SqlConnection("server = SERVERNAME; database = DBName; uid = sqluser;pwd= password ; connection timeout=0 ");
       
        strQry = strFmt("SELECT * FROM [DBname].[dbo].[TableName]  WHERE importflag = 0");

        cmd = new System.Data.SqlClient.SqlCommand(strQry,conn);
        conn.Open();

        dr =  cmd.ExecuteReader();      

        while(dr.Read())
        {
            try
            {          
                Empl = dr.get_Item('Employeecode'); // EmployeeCode is the SQL field name            
                transDate = dr1.get_Item('TransDate');
            }
            catch (Exception::Error)
            {
                info("Caught 'Exception::Error'.");
            }
        }
        dr.Close();
        conn.Close();
    }
    catch (Exception::Error)
    {
        info("Caught 'Exception::Error'.");
    }
    catch (Exception::CLRError)
    {
        info("Caught 'Exception::CLRError'.");
        netExcepn = CLRInterop::getLastException();
        info(netExcepn.ToString());
    }
}

Saturday, March 22, 2014

X++ code to create Project WBS template in AX 2012

static void TemplateUploadnew(Args _args)
{
            Hierarchy           Hierarchy;
            HierarchyTreeTable  HierarchyTreeTable;
            smmActivities       smmActivities;
            SysExcelApplication application;
            SysExcelWorkbooks workbooks;
            SysExcelWorkbook workbook;
            SysExcelWorksheets worksheets;
            SysExcelWorksheet worksheet;
            SysExcelCells cells;
            COMVariantType type;

            int                     row;
            int                     col;

            int                     refCol;
            FileName            filename;
            row = 2;
            application = SysExcelApplication::construct();
            workbooks = application.workbooks();
            filename = "D:\\Farook\\Temp.xlsx";
            try
            {
            workbooks.open(filename);
            }
            catch (Exception::Error)
            {
            throw error("File cannot be opened.");
            }

            workbook = workbooks.item(1);
            worksheets = workbook.worksheets();
            worksheet = worksheets.itemFromNum(1);
            cells = worksheet.cells();
            ttsBegin;
            do
            {

            if(cells.item(row, 1).value().bStr() != "")
            {

                Hierarchy.HierarchyId = cells.item(row, 1).value().bStr();
                Hierarchy.Name = cells.item(row, 2).value().bStr();
                Hierarchy.Description = cells.item(row,3).value().bStr();
                Hierarchy.Module = "TM";//cells.item(row, 4).value().bStr();
                Hierarchy.CountryId = cells.item(row, 4).value().bStr();
                Hierarchy.HierarchyType   =  HierarchyType::Project;
                Hierarchy.IsTemplate   =  NoYes::Yes;
                Hierarchy.IsActive = NoYes::Yes;
                // Hierarchy.Type   =str2enum('Registration');
                Hierarchy.insert();               


                row++;

                info(cells.item(row, 1).value().bStr());
            }
            else
            {
            application.quit();
            break;

            }


            }
            while (type == COMVariantType::VT_EMPTY);
            application.quit();
            ttsCommit;
            info(strFmt("%1 records imported",1));





}






static void TemplateUploadEstimates(Args _args)
{
            Hierarchy           Hierarchy;
    HierarchyNAme   name;
            HierarchyTreeTable  HierarchyTreeTable;
    PSAActivityEstimates    estimates;
    InventDim   inventDim;
    InventTable inventTable;
            smmActivities       smmActivities;
            SysExcelApplication application;
            SysExcelWorkbooks workbooks;
            SysExcelWorkbook workbook;
            SysExcelWorksheets worksheets;
            SysExcelWorksheet worksheet;
            SysExcelCells cells;
            COMVariantType type;

            int                     row;
            int                     col;
    int sno;

            int                     refCol;
            FileName            filename;
            row = 2;
            application = SysExcelApplication::construct();
            workbooks = application.workbooks();
            filename = "D:\\Farook\\Temp1.xlsx";
            try
            {
            workbooks.open(filename);
            }
            catch (Exception::Error)
            {
            throw error("File cannot be opened.");
            }

            workbook = workbooks.item(1);
            worksheets = workbook.worksheets();
            worksheet = worksheets.itemFromNum(1);
            cells = worksheet.cells();
            ttsBegin;
            do
            {

            if(cells.item(row, 1).value().double() != 0 )
            {
                name = cells.item(row, 2).value().bStr();
                sno = cells.item(row, 1).value().double();
                select firstOnly Hierarchy where Hierarchy.Name == name;               
               
                if(sno == 1)
                {
                    smmActivities.ActivityNumber  = 'A'+ Hierarchy.HierarchyId;
               
                smmActivities.IsTemplate  = NoYes::Yes;
                smmActivities.ActivityTaskTimeType  = smmActivityTaskTimeType::InProgress;
                smmActivities.ActivityTimeType = smmShowTimeAs::Busy;
                smmActivities.Category = smmActivityCategory::Task;
                smmActivities.IsTemplate    = NoYes::Yes;
                smmActivities.KeepSynchronized    = NoYes::Yes;
                smmActivities.Purpose = 'Activity';
                smmActivities.Sensitivity =   smmSensitivity::Normal;
                smmActivities.Source ='Microsoft Dynamics';
                smmActivities.insert();
                HierarchyTreeTable = HierarchyTreeTable::insertRoot(hierarchy.HierarchyId, hierarchy.Name);

                HierarchyTreeTable::insertActivity(hierarchy.HierarchyId,HierarchyTreeTable.ElementNumber,smmActivities);
                }
                estimates.ActivityNumber = smmActivities.ActivityNumber;
                estimates.Description = cells.item(row, 3).value().bStr();
                estimates.InventDimId = "DXB1-000022";
                estimates.ItemId = cells.item(row, 4).value().bStr();
                estimates.ProjCategoryId = cells.item(row, 5).value().bStr();
                estimates.ProjTransType = QuotationProjTransType::Item;
                estimates.Quantity = 1;
               
                   inventDim   = InventDim::find(estimates.InventDimId);
                 inventTable = InventTable::find(estimates.ItemId);
                estimates.UnitCostPrice  = inventTable.costPcsPrice(estimates.InventDimId, inventDim);

                estimates.UnitSalesPrice =  inventTable.salesPcsPrice();
                estimates.LinePropertyId = ProjCategory::find(estimates.ProjCategoryId,false).projLinePropertyId();
                estimates.insert();
                row++;

                info(cells.item(row, 1).value().bStr());
            }
            else
            {
            application.quit();
            break;

            }


            }
            while (type == COMVariantType::VT_EMPTY);
            application.quit();
            ttsCommit;
            info(strFmt("%1 records imported",1));




}

Wednesday, March 19, 2014

Sequence of methods in the FORM level in AX

This gives the information of method calls in the form level while
1. Opening the Form.
2. Creating/Updating/Deleting the record in the Form.
3. Closing the Form.
Sequence of Methods calls while opening the Form
Form --- init ()
Form --- Datasource --- init ()
Form --- run ()
Form --- Datasource --- execute Query ()
Form --- Datasource --- active ()

Sequence of Methods calls while closing the Form
Form --- canClose ()
Form --- close ()

Sequence of Methods calls while creating the record in the Form
Form --- Datasource --- create ()
Form --- Datasource --- initValue ()
Table --- initValue ()
Form --- Datasource --- active ()

Sequence of Method calls while saving the record in the Form
Form --- Datasource --- ValidateWrite ()
Table --- ValidateWrite ()
Form --- Datasource --- write ()
Table --- insert ()

Sequence of Method calls while deleting the record in the Form
Form --- Datasource --- validatedelete ()
Table --- validatedelete ()
Table --- delete ()
Form --- Datasource --- active ()

Sequence of Methods calls while modifying the fields in the Form
Table --- validateField ()
Table --- modifiedField ()

Monday, March 17, 2014

Full CIL and Incremental CIL in AX 2012

In AX development, it is a bit confusing about the real meaning of “Compile”, “generate Full CIL or incremental CIL”,

Compile: -The compile is to convert x++ source code into p-code, it is in 2009

Sync:-Checking each and every table defining the value of your EDT

Full CIL :-generate CIL is about to convert the p-code into CIL, referred to as the byte code which, at run time, is used by the CLR to convert into native code for execution on the computer. It is easier to understand that a full CIL generation involves converting all p-code into CIL, finally it converts to the binary Lang

Incremental CIL :-incremental CIL generation involves only the “changed” p-code artifacts that need  to be converted into target CIL. Incremental CIL would compile only the objects that were modified since the last incremental compilation.
Some X++ batch jobs can now complete in much less time. All X++ code that runs on the AX32.exe client still runs as interpreted p-code. However, all batch jobs now run as Microsoft .NET Framework CIL, which is often much faster than p-code.

The X++ developer must now complete the extra step of compiling X++ p-code to CIL. To compile p-code to CIL, right-click AOT, and then click Add-ins > Incremental CIL generation from X++.

Next, if the installation uses multiple instances of Application Object Server (AOS), all AOS instances must be stopped and then restarted. This causes the AOS instances to load the updated assembly.

Finally, a service or a batch job must run the X++ code that was compiled to CIL. Services and batch jobs now run only as CIL

Link and Join types in AX 2012

Link Type and Join Types in ax 2012

Link Type:-

1. Active: - Parent and child- data source is updated immediately when a new record in the parent data source is selected. Continuous updates consume lots of resources consuming.

2. Delayed: - Parent and child - A pause is inserted before linked child data sources are updated. This     enables faster navigation in the parent data source because the records from child data sources are not updated immediately. For example, you can scroll a list of orders where you do not want to review the lines associated with the order until you stop scrolling.

3. Passive: - Parent and child - Linked child data sources are not updated automatically. Updates of the child data source must be programmed on the active method of the master data source.


Join Types:-

1. InnerJoin: - Combined data source – select the record from the main table that matches records in the joined table and vice versa.
There is one record for each match. Records without related records in the other data source are eliminated from the result.

2. Outer Join: - Combined data source – select the records from the main table. The records are retrieved whether they have matching records in the joined table

3. Exist Join: - Combined data source -The data source retrieves a record from the main table for each matching record in the joined table.
The differences between InnerJoin and ExistJoin are as follows:
·         When the join type is ExistJoin, the search ends after the first match has been found.
·         When the join type is InnerJoin, all matching records are searched for.

4. NotExistJoin: - Combined data source -Select records from the main table that do not have a match in the joined table.


For more information:-

http://axapta4u.blogspot.in/2013/06/joins-and-linktypes-in-axapta.html