Showing posts with label Microsoft Dynamics. Show all posts
Showing posts with label Microsoft Dynamics. Show all posts

Thursday, August 5, 2010

Calling method at runtime

In Dynamics AX, you can decide at runtime whether you need to call a method or not. See example below in which the find method of CustTable is called at runtime.

static void invokeMethodOnRunTime(Args _args)
{
   DictTable dictTable = new DictTable(tablenum(CustTable));
   CustTable custTable;
   //Check if class/table has method

   if(tableHasStaticMethod(dictTable, identifierstr('find')))
  {
       custTable = dictTable.callStatic(tableStaticMethodStr(CustTable, Find), '4000');
       info(custTable.name());
  }

}

Monday, August 2, 2010

Getting number of rows loaded

To get the number of rows loaded to the Dynamics AX datasource, you can use the following function of the datasource.

[datasource].numberOfRowsLoaded();

For example:

custTable_ds.numberOfRowsLoaded();

Thursday, July 22, 2010

Modify label of Runbase OK button

There are number of requirements when a developer wants to change the label of runbase dialog OK button in Dynamics AX. You can use the following code to change the label of OK button on Runbase dialog in AX

Insert the following code after the super() call in the putToDialog method

protected void putToDialog()
{
FormBuildCommandButtonControl commandButton;
;
super();
commandButton = dialog.dialogForm().control("OkButton");

commandButton.text("Yes");

}

Tuesday, July 20, 2010

Multi Tab Lookups in AX

Lets say you  have a requirement in which you want to show multiple tabs on a lookup form. For example,  you have a field in which you want your user to either select a customer or vendor from a lookup then this could be the best option to show multiple tabs and let user select either customer or vendor.

Following are the steps to get this done.

* Create a new form "LookupForm" with multiple tabs on it.
* The FormHelp property of the EDT should be set to the form you just created "LookupForm".
Its all done!!! this is how lookup will look like

Multi tab lookup

Sunday, July 11, 2010

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 se_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();
}
}

Tuesday, July 6, 2010

Conditional Joins in x++

In this post, we will try to learn how we can apply conditional joins in x++ to cater the complex scenarios in the development of Microsoft Dynamics AX.

Conditional joins in Dynamics AX (x++)
Here is the code to apply joins conditionally in Microsoft Dynamics AX.
query = new Query();
dsInventTable = query.addDataSource(tableNum(InventTable), "InventTable");
dsInventItemBarCode = dsInventTable.addDataSource(tableNum(InventItemBarCode), "InventItemBarCode");
dsInventItemBarCode.joinMode(JoinMode::ExistsJoin);

// Add our two ranges
queryBuildRange1 = dsInventTable.addRange(fieldNum(InventTable, DataAreaId));
queryBuildRange2 = dsInventItemBarCode.addRange(fieldNum(InventItemBarCode, DataAreaId));
 


No we can play with our query  
Find all records where either the ItemType is Service, or the ItemType is Item and a barcode exists. The join criteria is only applied in the second half of the expression, so all Service items will appear irrespective of whether they have a bar code. Again, this is not possible to achieve using the standard query ranges.

queryBuildRange2.value(strFmt('((%1.%2 == %3) || ((%1.%2 == %4) && (%1.%5 == %6)))',
query.dataSourceTable(tableNum(InventTable)).name(), // InventTable %1
fieldStr(InventTable, ItemType), // ItemType %2
any2int(ItemType::Service), // %3
any2int(ItemType::Item), // %4
fieldStr(InventTable, ItemId), // ItemId %5
fieldStr(InventItemBarCode, ItemId))); // %6

Wednesday, June 2, 2010

Welcome

Welcome to the Dynamics AX blog.

Here we are going to discuss Dynamics AX functional and technical issue and I will be sharing some tips and tricks that we use during the development of Dynamics Ax projects.
The main goal is to learn the tips and tricks and to provide the help on the topics that are not available on google right now.
Best wishes,
Yasir Godil
Developer, Microsoft Dynamics AX - Public Sector team.