Friday, 17 February 2017

Microsoft Dynamics® AX 7 Development Basics

Before we talk AX7 Development, we need to have look at few terminologies, which are as under

Element: Element is any Object residing in AOT. E.g. any Base Enumeration, any EDT, any Table, any Form, which you see in AOT Tree, is an element itself.

Model: A Model is a group of elements. A model is collection of elements that represent a distributable software solution.

Packages: A package is deployable unit, which may have multiple Models.

Project: Projects are the logical containers for everything that's needed to build your application. A project can be associated with only one model.

After we know basic terminologies, which will be used very frequently, let’s start with ways of developments AX7 provides.

With arrival of AX7, now we can do development in AX, with two methodologies.

  1. OverLayring
    If you have been developer of previous versions of AX such as AX2012 or AX2009, you don’t need explanation of this way of development. Name of this methodology ‘OverLayring’ is self-explanatory.
    In Microsoft Dynamics AX, a layer system is used to manage elements. The USR layer is the top layer and the SYS layer is the bottom layer, and each layer has a corresponding patch layer above it.
    OverLayring means if you do change/customize any element in upper layer, it will override its definition, in lower layer.
    This is what we were doing till AX2012 to customize AX. It basically allows customization of metadata and source code in higher layer. For example, you can add a new field in CustTrans Table in the user layer or in ISV Layer.
  2. Extension
    It refers to concept of extending existing elements, without overriding those into other layers. That means, elements will not be customized, instead elements will be extended. This approach reduces upgrade cost and conflicts. By creating extension elements, all of the customizations and code are stored in a separate assembly. It only contains the code that was added or changed in the extension file. Since this code resides in a separate assembly, it improves performance and the ability to upgrade and test.

Tuesday, 31 January 2017

Item Default Site order setting through X++ code in ax 2009

Before that we need one Excel work book in that first column need to fill the Item numbers.
then use this job.

static void Item_Default_Site(Args _args)
{
        SysExcelApplication             application;
        SysExcelWorkbooks               workbooks;
        SysExcelWorkbook                workbook;
        SysExcelWorksheets              worksheets;
        SysExcelWorksheet               worksheet;
        SysExcelCells                   cells;
        COMVariantType                  type;
        System.DateTime                 ShlefDate;
        FilenameOpen                    filename;
        dialogField                     dialogFilename;
        Dialog                          dialog;
        //Table Declarations Starts
        DlvMode                        dlvMode;
        str ItemNum;
        InventTable             inventTable;
        InventItemInventSetup   inventItemInventSetup;
        InventItemPurchSetup    inventItemPurchSetup;
        InventItemSalesSetup    inventItemSalesSetup;
        InventDim               inventDim;

        //Table Declartions Ends
        int                             row;
        #Excel
        // convert into str from excel cell value
    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_R4):
        return num2str(_cv.float(),_characters,_decimals,_separator1,_separator2);
        case (COMVariantType::VT_R8):
        return num2str(_cv.double(),_characters,_decimals,_separator1,_separator2);
        case (COMVariantType::VT_DECIMAL):
        return num2str(_cv.decimal(),_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()));
        }
        return "";
        }
        ;
        dialog              =   new Dialog("Excel Upoad");
        dialogFilename      =   dialog.addField(typeId(FilenameOpen));
       // dialog.filenameLookupFilter(["@SYS28576″,#XLSX,"@SYS28576",#XLS]);
        dialog.filenameLookupTitle("Upload from Excel");
        dialog.caption("Excel Upload");
        dialogFilename.value(filename);
        if(!dialog.run())
        return;
        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++;
        itemNum =(COMVariant2Str(cells.item(row,1).value()));
        #define.itemId(itemNum)
       // inventTable.ItemId = COMVariant2Str(cells.item(row,1).value());
          inventTable = InventTable::find(#itemId);
     #define.siteId('XXX')
       if(row > 1)
        {
        //Insert into InventSize Table
         if(inventTable.ItemId)
          {
             ttsBegin;

        inventDim.initValue();
        inventDim.InventSiteId = #siteId;
        inventDim = InventDim::findOrCreate(inventDim);

        //InventItemSalesSetup
        inventItemSalesSetup.clear();
        inventItemSalesSetup.initValue();
        inventItemSalesSetup.ItemId = inventTable.ItemId;
        inventItemSalesSetup.InventDimId = InventDim::inventDimIdBlank();
        inventItemSalesSetup.InventDimIdDefault = inventDim.inventDimId;
        inventItemSalesSetup.insert();

        //InventItemInventSetup
        inventItemInventSetup.clear();
        inventItemInventSetup.initValue();
        inventItemInventSetup.ItemId = inventTable.ItemId;
        inventItemInventSetup.InventDimId = InventDim::inventDimIdBlank();
        inventItemInventSetup.InventDimIdDefault = inventDim.inventDimId;
        inventItemInventSetup.insert();

        //InventItemPurchSetup
        inventItemPurchSetup.clear();
        inventItemPurchSetup.initValue();
        inventItemPurchSetup.ItemId = inventTable.ItemId;
        inventItemPurchSetup.InventDimId = InventDim::inventDimIdBlank();
        inventItemPurchSetup.InventDimIdDefault = inventDim.inventDimId;
//        inventItemPurchSetup.inventSiteId()
        inventItemPurchSetup.insert();
        ttscommit;
        }

         info(strfmt(" uploaded successfully"));
        }
        type = cells.item(row+1, 1).value().variantType();
        }while (type != COMVariantType::VT_EMPTY);
        application.quit();
        ttscommit;
        }
        catch
        {
        Error("Upload Failed");
}
}

Wednesday, 19 October 2016

import-customer-mastervendor-master-and-their-primary-addresses on Ax 2009

https://shekhardiptiman.wordpress.com/2010/01/14/dynamics-ax-2009-%E2%80%93-import-customer-mastervendor-master-and-their-primary-addresses/

Friday, 30 September 2016

passing parameters between forms in AX

https://calebmsdax.wordpress.com/2013/02/22/passing-parameters-between-forms-in-ax/

Tuesday, 27 September 2016

Copy user groups from one user to another X++ in ax



//Copy user groups from one user to another X++
static void KR_AXEcopyUserGroup(Args _args)
{
    usergrouplist usergrouplist,ins;
    userid src,dest;
    dialogfield srcdf,destdf;
    dialog dialog;
    ;
    dialog = new dialog("copying user's user groups");
    srcdf = dialog.addField(typeid(userid),"Source");
    destdf = dialog.addField(typeid(userid),"Destination");



    if(dialog.run())
    {
        src = srcdf.value();
        dest = destdf.value();
        if(src!="" && dest !="")
        {
            ttsbegin;
            while select * from usergrouplist
            where usergrouplist.userId == dest
            {
                info(strfmt("Before update: '%1'-'%2'",usergrouplist.userid,usergrouplist.groupId));
            }

            info("Deleting user groups from destination user");
            delete_from usergrouplist
                where  usergrouplist.userId == dest;


            info("Copying user groups to destination user");
            while select * from usergrouplist
            where usergrouplist.userId == src
            {
                info(strfmt("source user: '%1'-'%2'",usergrouplist.userid,usergrouplist.groupId));
                ins.clear();
                ins.data(usergrouplist);
                ins.UserId = dest;
                ins.insert();
            }
            ttscommit;
            info("User groups has been copied!");
        }
    }
    else
    {
        info("Canceled by user");
    }


}

Sunday, 11 September 2016