June 04, 2013

Finding AOT object by its propery

Finding AOT object by its propery

In Dynamics AX we can find all the AOT objects by specifying some property. Lets say we want to find all the tables in AOT having "SaveDataPerCompany" property set to No.
We can use the following x++ job
The X++ job below shows how to find all tables in the AOT where the SaveDataPerCompany property is set to No.


static void findAOTObjectByProperty(Args _args)
{
#AOT
TreeNode treeNodeTables = TreeNode::findNode(#TablesPath);
TreeNode treeNode;
str strPropertyName = 'SaveDataPerCompany';
str strPropertyValue = 'No';
;
// first table
treeNode = treeNodeTables.AOTfirstChild();
while (treeNode != null)
{
if (treeNode.AOTgetProperty(strPropertyName)== strPropertyValue)
{
info(treeNode.AOTname());
}
// next table
treeNode = treeNode.AOTnextSibling();
}
}


You can search other property by modify below line of code
 "treeNode.AOTgetProperty(strPropertyName)== strPropertyValue"

-Harry

May 24, 2013

Custom lookup for Dialog fields in Axapta [AX2012]

Custom lookup for Dialog fields in Axapta





Overriding the event methods (e.g. custom lookup, modify, validate, selectionChange) on dialog controls is not as straight forward as it is on form controls, but the good news is that it is possible!
In order to override the event methods on dialog controls, the following needs to be done.
class TestDialogFields
{
    Dialog                   dialog;  
    DialogField           newProdIdField;
}
public static void main(Args args)
{
    TestDialogFieldstestDialogFields = new TestDialogFields();
     DialogRunbase               dialogRunbase;
    ;
    dialogRunbase = DialogControlOverload.showDialog();
    if(dialogRunbase.run())
    {
        // code for update  once the use selects a record from the lookup and click 'ok'
     }
}
Dialog showDialog()
{
    FormRun     formRun;
    ;
    dialog = new Dialog('Dialog fields test');
    newProdIdField = dialog.addField(typeId(ProdId));
    dialog.run(true);
    dialog.formRun().controlMethodOverload(true);
    dialog.formRun().controlMethodOverloadObject(this);
    return dialog;
}
If we want to create a Custom lookup
public void Fld1_1_lookup()
{
    FormStringControl control = dialog.formRun().controlCallingMethod();
    boolean ret;
    SysTableLookup          sysTableLookup =  SysTableLookup::newParameters(tablenum(Prodtable, control);
    Query                   query = new Query();
    QueryBuildDataSource    queryBuildDataSource;
    QueryBuildRange         queryBuildRange;
    ProdTable               prodTable;
     ;
   prodTable = ProdTable::find(prodId);
sysTableLookup.addLookupfield(fieldnum(ProdTable, ProdId));
    sysTableLookup.addLookupfield(fieldnum(ProdTable, Name));
  //You can add the ranges for filtering
   sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}
We can add all the other methods  as follows
public void Fld1_1_modified()
{
  // modify code goes here
}
public void Fld1_1_validate()
{
// validation code goes here
}
 
-Harry