Wednesday, August 22, 2018

ECORESCATEGORY Table in Dynamics-SSC -Vikas Mehta MULTISELECT

ECORESCATEGORY Table in Dynamics-SSC

Query to get the ecorescategory branches and nodes in ax 2012 

  this.parmQuery().dataSourceTable(tablenum(EcoResCategory), 1).clearRanges();
        categoryBuildRange = this.parmQuery().dataSourceTable(tablenum(EcoResCategory), 1).addRange(fieldnum(EcoResCategory, RecId));

        categoryEnum = category.getEnumerator();
        while (categoryEnum.moveNext())
        {
            categoryRecid = categoryEnum.current();
            select ecoResCategory where ecoResCategory.RecId == categoryRecid;
            currentLevel = ecoResCategory.Level;
            lowestlevel = ecoResCategory.getLowestLevel();
            categoryHierarchy = ecoResCategory.CategoryHierarchy;
            while(currentLevel <= lowestlevel)
            {
            while select ecoResCategoryChild where ecoResCategoryChild.CategoryHierarchy == categoryHierarchy
                                                && ecoResCategoryChild.Level ==  currentLevel
            {
                categoryRecid = ecoResCategoryChild.RecId;
                while select * from ecoResCat
                    order by ecoResCat.NestedSetLeft
                    where   ecoResCat.CategoryHierarchy == ecoResCategoryChild.CategoryHierarchy
                            && ecoResCat.NestedSetLeft  <= ecoResCategoryChild.NestedSetLeft
                            && ecoResCat.NestedSetRight >= ecoResCategoryChild.NestedSetRight
                {
                    if(ecoResCategory.RecId == ecoResCat.RecId)
                    {
                        select * from ecoResCategoryisLeaf
                            order by ecoResCategoryisLeaf.Name
                            where   ecoResCategoryisLeaf.CategoryHierarchy == ecoResCategoryChild.CategoryHierarchy
                             && ecoResCategoryisLeaf.ParentCategory  == ecoResCategoryChild.RecId
                                && ecoResCategoryisLeaf.IsActive == true;

                        if(!ecoResCategoryisLeaf)
                        {
                            allCategory.addEnd(categoryRecid);
                        }
                        break;
                    }
                }
            }
            currentLevel++;
        }


        }
 

Item lookup of ecorescategory in ui builder class

private void itemLookup(FormStringControl _control)
{
    Query query;
    QueryBuildDataSource qbdscategory,qbdsProductCategory,qbdsInvent,qbdsEcoProduct;
    container brandCon;
    int counter;
    RecId brandCategoryRecid,categoryRecid,segmentRecid;
    EcoResCategory category,segmentCategory;
    ;
    query = new query();
    qbdsInvent = query.addDataSource(tableNum(InventTable));
    qbdsEcoProduct = qbdsInvent.addDataSource(tableNum(EcoResProduct));
    qbdsEcoProduct.relations(false);
    qbdsEcoProduct.addLink(fieldNum(EcoResProduct,RecId),fieldNum(InventTable,Product));

    qbdsProductCategory = qbdsEcoProduct.addDataSource(tableNum(EcoResProductCategory));
    qbdsProductCategory.relations(false);
    qbdsProductCategory.addLink(fieldNum(EcoResProduct,RecId),fieldNum(EcoResProductCategory,Product));

    qbdscategory = qbdsProductCategory.addDataSource(tableNum(EcoResCategory));
    qbdscategory.relations(false);
    qbdscategory.addLink(fieldNum(EcoResProductCategory,Category),fieldNum(EcoResCategory,RecId));

 ECORESCATEGORY LOOKUP MULTISELECT

public void categoryLookup()
{
    Query           query = new Query(querystr(ProcCategoryEcoResCategory));
    int             mutiSelectTableNum = tablenum(EcoResCategory);

    container selectedFields = [mutiSelectTableNum, fieldname2id(mutiSelectTableNum, fieldstr(EcoResCategory, Name))];

    SysLookupMultiSelectCtrl::constructWithQuery(this.dialog().dialogForm().formRun(), categoryField.control(), query, false, selectedFields);
}

Method checkbox in Dynamics AX -Map Vikas Mehta

Method checkbox in Dynamics AX -Map ssc

Below is the method to select the records which are being selected as a method checkbox in the standard system in AX.
A map needs to be declared initially which needs to be initialized on init.


Map                                 gSelectedInventSum;
On init
gSelectedInventSum = new Map(Types::String, Types::Record);

this method needs to be written on the form design to get the selected record.
 
On selection
public edit boolean selectInventSum(
        boolean         _set,
        InventSum       _inventSum,
        boolean         _select)
{
    boolean inventSumSelected;
    InventDim dim = _inventSum.joinChild();

    inventSumSelected = gSelectedInventSum.exists(dim.inventBatchId);
    if (_set)
    {
        if (_select)
        {
            if (!inventSumSelected)
            {
                gSelectedInventSum.insert(dim.inventBatchId, dim);
            }
        }
        else
        {
            if (inventSumSelected)
            {
                gSelectedInventSum.remove(dim.inventBatchId);
            }
        }
    }

    return gSelectedInventSum.exists(dim.inventBatchId);
}
 Inorder to get the selected records on a button click use the below method
void clicked()
{
    int                     ret;
   InventDim               dim;
    InventDimParm           dimParm;
    MapEnumerator           enum;
    List                    receiptList;


    super();

        enum = gSelectedInventSum.getEnumerator();

        while (enum.moveNext())
        {
        dim = enum.currentValue();
        dim = InventDim::findOrCreate(dim);
        info(strFmt("item : %1,dim %2",inventSum.ItemId,dim.inventBatchId));

        }
 }
 Another way to get the items and  process further is as below
public int showContextMenu(int _menuHandle)
{
    int                     ret;
    inventSumSelector;
    receipt;
    InventDim               dim;
    InventDimParm           dimParm;
    MapEnumerator           enum;
    List                    receiptList;
             
    view = gCurrentView;

    item = gTree.getTreeItem(this.getSelection());
    if (gSelectedInventSum.empty())
    {
        dim = InventSum.joinChild();
        dim = InventDim::findOrCreate(dim);
        dimParm.initFromInventDim(dim);
        dimParm.InventBatchIdFlag = false;
         }
    else
    {
        enum = gSelectedInventSum.getEnumerator();
        receiptList = new List (Types::Class);
        while (enum.moveNext())
        {
            dim = enum.currentValue();
            dim = InventDim::findOrCreate(dim);
            dimParm.initFromInventDim(dim);
            receipt = //;
            receiptList.addEnd(receipt);
        }

    }
   
    return ret;
}
Related Posts Plugin for WordPress, Blogger...