Quantcast
Channel: Santosh Kumar Paruvella's Blog » DynamicsAx Utilities
Viewing all articles
Browse latest Browse all 8

Dimension (Field Value) Search Utility in Dynamics Ax

$
0
0

In recent days, I got a specific requirement…

At our place, finance controller has decided to close one dimension value and need to replace the same with new dimension value.

To support this, we need to update all the transactions which have old dimension value, to new one.

Assume all the transactions, which are created Dimension [10] – Business unit with value 201, need to update as 203

static void ininspar_Dimension201_Update_Alltables(Args _args)
{
    TreeNode                tn,fn;
    TreeNodeIterator        tni,fni,_tni;
    Str                     objName;
    SysDictField            sysDictField;
    Common                  common;
    Query                   query = new Query();
    QueryBuildDataSource    qbs;
    QueryBuildRange         qbr;
    TableId                 mTableId;
    QueryRun                qr;
    ;

    tn = TreeNode::findNode(“\\Data Dictionary\\Tables”);
    tni = tn.AOTiterator();
    tn = tni.next();

    while (tn)
    {
        objName = tn.treeNodeName();

        tn = tni.next();

        mTableId = tableName2id(objName);
        sysDictField = new SysDictField(mTableId, fieldname2id(mTableId, “Dimension”));  // Finding table object which have Dimension field

        if (sysDictField && Global::hasTableAccess(mTableId))
        {
            //info(objname);
            try
            {
                qbs = query.addDataSource(mTableId);
                qbr = qbs.addRange(fieldId2Ext(fieldname2id(mTableId, “Dimension”),10));   // using Dimension[10] in query range
                qbr.value(“201″);

                qr = new QueryRun(query);
                while (qr.next())
                {

                    common = qr.get(mTableId);
                    if (common.RecId)
                    {
                        common.selectForUpdate(true);
                        ttsbegin;
                        common.(fieldId2Ext(fieldname2id(mTableId, “Dimension”),10)) = “203″; //assigning the Dimension[10] value by using Common
                        common.update();
                        ttscommit;
                        info(strfmt(“%1 %2″,objName, int2str(common.RecId)));
                    }
                }
            }
            catch(Exception::Error)
            {
                continue;
            }

        }
    }
}

 

With this, we can write some Advanced Search utilities, to find specific values for some fields for the tables.



Viewing all articles
Browse latest Browse all 8

Latest Images

Trending Articles





Latest Images