Dynamics AX Blog - Page 8
Sort Query by financial dimensionYou can use the SysQuery::addOrderByDimensionAttribute() method to sort a query on a financial dimension.
static void sortByDimension(Args _args)
{
Query query;
QueryRun queryRun;
QueryBuildDataSource qbds;
CustTable custTable;
DimensionComponent dimensionComponent;
DimensionValue dimensionValue;
#define.CostCenterDimensionName("CostCenter");
query = new Query();
qbds = query.addDataSource(tableNum(CustTable));
SysQuery::addOrderByDimensionAttribute(query,
qbds.name(),
fieldId2name(tableNum(CustTable),
fieldNum(CustTable, DefaultDimension)),
DimensionComponent::DimensionAttribute,
SortOrder::Ascending,
#CostCenterDimensionName);
queryRun = new QueryRun(query);
while(queryRun.next())
{
custTable = queryRun.get(tableNum(CustTable));
// Get dimension value
dimensionValue =
(select firstonly DisplayValue from defaultDimensionView
where defaultDimensionView.Name == #CostCenterDimensionName
&& defaultDimensionView.DefaultDimension == custTable.DefaultDimension).DisplayValue;
info(strFmt("%1 %2", custTable.AccountNum, dimensionValue));
}
} |
Caching display methodsThe fact that display methods should be cached, when they are used in forms, is well-known. For this, a corresponding call should always be integrated into the init() method of a form datasource:
public void init()
{
super();
this.cacheAddMethod(tableMethodStr(DirPartyPostalAddressView,locationRoles));
}
The fact that you can save this call in Dynamics AX 2012, if you set a corresponding attribute in the display method itself, was new to me: |
Entitle SysOperation classes with the help of code PermissionsIf you want to setup the security for a function, which is based on the Sysperation framework, by using a Code permission, the following steps are necessary:
Picture: Step 4
More info at MSDN. |
Find missing labels in a specific languageRecently, I had to find out if a label exists in a certain language (in the example de_at), or not. Well suited for it seems the following SQL statement. SELECT * FROM [AX2012R3_TEST_model].[dbo].[ModelElementLabel] as existing where existing.Module = 'myModule' and existing.Language = 'en_us' and not exists ( select * from [AX2012R3_TEST_model].[dbo].[ModelElementLabel] as missing where missing.labelid = existing.LabelId and missing.Module = existing.Module and missing.Language = 'de_at') |
Detect/Respond on changing the edit modeTo respond in a form to change the edit mode, you can see the task () - Override method of the form as follows:
public int task(int _taskId)
{
int ret;
#Task
ret = super(_taskId);
switch(_taskId)
{
case #taskEditRecord:
…doSomething…
break;
}
return ret;
}
To get the current edit mode you may use the following method: element.inViewMode() |
Use special characters in the XML-header of a methodSometimes you have to use special characters in the XML header of a method to document the code well. To get sure, that this header is still well-formed and is not identified as best practice deviation, you can use a CDATA section.
/// <version>
/// 1.0
/// </version>
/// <summary>
/// <![CDATA[ Replaces following special characters: &, % ]]>
/// </summary>
private void someMethod()
{
//...do something...
}
Without this CDATA section AX would spend the following BP-Deviation:
|
|
|
|
|
|
|

For the first time, I had the requirement to implement a simple field validation in the Mobile Device Portal (MDP). After I have tried something with the WHSWorkExecute class, I have found the class method WHSRFControlData.processData() as well suited for such type of exams.
Such an examination could look as follows:
case #Qty: qty = WHSWorkExecuteDisplay::str2numDisplay(data); if (qty <= 0) { errorMessage = "@WAX1172"; hasError = true; break; } //--> Start if (pass.exists(#ProdId) && pass.lookupStr(#ProdId) != "" && mode == WHSWorkExecuteMode::ReportAsFinished) { my_ProdTable = ProdTable::find(pass.lookup(#ProdId)); if (qty + my_ProdTable.reportedFinishedGood() + my_ProdTable.reportedFinishedError() > my_ProdTable.QtyStUp) { errorMessage = "@SYS16097"; hasError = true; break; } } //<-- End