Tuesday, August 31, 2010

Renaming the Primary Key through code

static void RenamePrimaryKey(Args _args)


{

         LedgerTable ledgerTable;
         ;
         select firstonly ledgerTable
                  where ledgerTable.AccountNum == '01010';
         if(ledgerTable.RecId)
        {
                 ledgerTable.AccountNum = 'K' + ledgerTable.AccountNum;
                 ledgerTable.renamePrimaryKey();
        }
        info(ledgerTable.AccountNum);
}

Sunday, August 22, 2010

Creating the Table and table fields in AOT through code

static void CreatingTable(Args _args)


{

       TreeNode               treeNode;

      AOTTableFieldList  fieldList;

      AccountNum          AccountNum;

      int                           field;

       ;



       //Finding the path for tables from the Data Dictionary...

        treeNode = TreeNode::findNode(@'\Data Dictionary\Tables\');

        treeNode.AOTfindChild('Tables');

        //Adding the new table...

        treeNode.AOTadd('Axapta');



        //Finding the new table which added in the above code...

        treeNode.AOTfindChild('Axapta');

       //adding the fields in the new created table...

        for(field = 1 ; field <= 10 ; field++)

       {

            fieldList = treeNode.AOTfindChild('Axapta').AOTfindChild('fields');

            fieldList.addString('field');

       }

}

Saturday, August 14, 2010

Link the two Data Source by using Query...

static void Query(Args _args)
{
    Query                              q;
    QueryRun                        qr;
    QueryBuildDataSource    custDataSource,transDataSource;
    QueryBuildRange            qbr;
    QueryBuildLink               qbl;
    CustTable                       custTable;
    CustTrans                       custTrans;
    ;
    q = new Query();
  
    //Adding the parent DataSource
    custDataSource  = q.addDataSource(tablenum(CustTable));
  
    //Adding the range
    qbr                    = custDataSource.addRange(fieldnum(CustTable,AccountNum));
    custDataSource.addSortField(fieldnum(CustTable,AccountNum));
  
    transDataSource = custDataSource.addDataSource(tablenum(custTrans));

    //Adding the Inner join for the two tables CustTable and CustTrans
    transDataSource.joinMode(JoinMode::InnerJoin);
  
    //Adding the relation for the two tables
    //If the realtion doesn't exists
    qbl             =
    transDataSource.addLink(fieldnum(CustTable,AccountNum),fieldnum(CustTrans,Accountnum));
  
    //If the relation already exists for the two tables in the table level...
    //Then we can use the following one...
    transDataSource.relations(true);

    qr = new QueryRun(q);
    while(qr.next())
    {
        //Logic to print the data from query..
    }
}