donderdag 20 november 2014

Find projects that include a specific AOT object

static void FindWhatProjectsObjectExistsIn(Args _args)
{
    ProjectNode         pn;
    ProjectListNode     projectListNode;

    TreeNode            tn, tn2;
    TreeNodeIterator    tni, tni2;

    // Object we are searching for
    TreeNode            tnSearch = TreeNode::findNode(@'\Forms\SalesTable');
    ;

    projectListNode = SysTreeNode::getSharedProject();
    tni = projectListNode.AOTiterator();

    tn = tni.next();

    while (tn)
    {
        pn = tn; // ProjectNode inherits TreeNode
        pn = pn.loadForInspection();

        tni2 = pn.AOTiterator();

        tn2 = tni2.next();

        while (tn2)
        {
            if (tn2.treeNodePath() == tnSearch.treeNodePath())
                info(strfmt("Found in shared project %1", tn.AOTname()));

            // info(tn2.applObjectType()); // Returns the type (Form/Class/Table/Etc)
            // info(tn2.AOTname()); // Returns the object name
            // info(tn2.treeNodePath()); // Returns the object path
            
            tn2 = tni2.next();
        }

        tn = tni.next();
    }
}
 

maandag 13 oktober 2014

Foreground / Background - Report ‘shape’ control issues with PDF Printer

The issue is that ‘shapes’ on reports need to be placed first in their section (first from top to bottom) for the PDF printer to be able to display the text over the shape. It’s a back to front thing where ‘back to front’ corresponds to ‘top to bottom’ on the AX report section.

Source: http://gatesasbait.wordpress.com/2008/09/08/report-shape-control-issues-with-pdf-printer-class-in-dynamics-ax-4-0/

maandag 8 juli 2013

Dimension (Field Value) Search Utility in Dynamics Ax

Source: http://paruvellas.wordpress.com/2012/03/15/dimension-field-value-search-utility-in-dynamics-ax/

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.

donderdag 4 juli 2013

Force delete inventtrans

Source: http://agusriyadi.blogspot.be/2009/08/force-delete-inventtrans.html

Below is sample job to force delete inventtrans, which will take care of invent on hand update.
static void DeleteInventTrans(Args _args)
{
Dialog dlg = new Dialog("Delete inventtrans ?");
DialogField dlgFld;
InventMovement inventMovement;
PurchLine purchLine;
PurchLineRefRecId recId;
;
dlgFld = dlg.addField(typeid(PurchLineRefRecId));
if(dlg.run())
{
recId = dlgFld.value();
purchLine = PurchLine::findRecId(recId);
if(purchLine)
{
InventMovement = InventMovement::construct(purchLine);
InventUpd_DeleteMovement::newMovement(
inventMovement,true).updateNow();
info("done");
}
}
}