Dynamics AX Blog - Axapta 2.5
RSS-Feed of this version
Use macro within a SELECT statementThe SELECT-Statement in the example lists only active BOM items (Table BOM) on (active using the fields FromDate and ToDate). If the second parameter of the macro is empty (zero date ()), so all BOM items are listed. static void useMacroInSelectStatement(Args _args) { bom bom; date emptyDate; // parameters: %1 = table instance, %2 date, %3 empty date value #localmacro.bomDateFilter && ( %2 == dateNull() || ( ((%1.FromDate <= %2) && (%1.ToDate >= %2)) || ((%1.FromDate == %3) && (%1.ToDate == %3)) || ((%1.FromDate <= %2) && (%1.ToDate == %3)) || ((%1.FromDate == %3) && (%1.ToDate >= %2)) )) #endMacro ; while select bom where bom.ItemId == '123' #bomDateFilter(bom, systemDateGet(), emptyDate) { info(bom.bomid); } } |
Which fields are shown in an auto-generated lookup?I was asked this question recently and was not able to answer. But i still knew that i had seen a page where this is explained in detail. But i knew neither find it manually nor using various search engines. But in old documents of mine i found the source then, the trick to find it using search engines, is using the old name of Microsoft Dynamics AX - Axapta to look for it! Do this, you will quickly find following page: |
Example of a date filter in a form DataSourceThe following code is an example of how to build a query range based on a Form Data Source, which displays only "daily" records. In the example the form-dataSource is named DataSourceName and it contains two date fields called FromDate and ToDate. Depending on a check box only records should be displayed, which that are valid for todays date. public void applyFilter()
{ queryBuildRange qbr; qbr = sysQuery::findOrCreateRange(DataSourceName_ds.queryBuildDataSource(), fieldNum(DataSourceName, recId)); if( !ShowExpiredCheckBox.checked()) { qbr.value(strfmt('('+ '((%5.%2 <= %1) && (%5.%3 >= %1)) || ' + '((%5.%2 == %4) && (%5.%3 == %4)) || ' + '((%5.%2 <= %1) && (%5.%3 == %4)) || ' + '((%5.%3 >= %1) && (%5.%2 == %4)) ' + ')', Date2StrXpp(systemDateGet()), fieldstr(DataSourceName, FromDate), fieldstr(DataSourceName, ToDate), Date2StrXpp(dateNull()), tableId2name(tableNum(DataSourceName)))); } else { qbr.value(SysQuery::valueUnlimited()); } } The above method can be called for example in the executeQuery() of the DataSource. |
Working with the calling object of a form (Caller)The following method contains some snippets that can be used to call various functions/methods of the calling object (form). If you change element.args() to e.g. _args and pass the arguments to the method, you can use the code within a class as well. void workWithCallingRecord() { common common; object object; formDataSource formDataSource; formRun formRun; inventDim inventDim; salesTable salesTable; int i; ; // Call method from calling record if( element.args() && element.args().record() ) { common = element.args().record(); if(common.isFormDataSource()) { info(tableId2Name(common.TableId)); if(formDataSourceHasMethod(common.dataSource(), identifierStr("someMethod"))) { object = common.dataSource(); object.someMethod(); } } } // Call method from calling form if(element.args() && element.args().caller() && element.args().caller().handle() == className2Id('formRun')) { formRun = element.args().caller(); if(sysFormRun::hasMethod(formRun, identifierStr("someFormMethod"))) { object = formRun; object.someFormMethod(); } } // Get value from calling record if( element.args() && element.args().record() ) { common = element.args().record(); if(common.TableId == tableNum(salesTable)) { info(common.(fieldNum(salesTable, salesId))); } } // Get value from calling datasource (form with multiple datasources) if(element.args() && element.args().caller() && element.args().caller().handle() == className2Id('formRun')) { formRun = element.args().caller(); for (i = 0; i <= formRun.dataSourceCount(); i++) { formDataSource = formRun.datasource(i); if (formDataSource && formDataSource.table() == tablenum(inventDim)) // Search for specific table { inventDim = formDataSource.cursor(); break; } } if(inventDim) { info(inventDim.InventLocationId); } } // Change data in calling datasource if(element.args() && element.args().caller() && element.args().caller().handle() == className2Id('formRun')) { formRun = element.args().caller(); for (i = 0; i <= formRun.dataSourceCount(); i++) { formDataSource = formRun.datasource(i); if (formDataSource && formDataSource.table() == tablenum(salesTable)) // Search for specific table { salesTable = formDataSource.cursor(); break; } } if(salesTable) { // Update data salesTable.PurchOrderFormNum = "Some value"; salesTable.update(); } } // Refresh calling datasource if( element.args() && element.args().record() ) { common = element.args().record(); if(common.isFormDataSource()) { formDataSource = common.dataSource(); formDataSource.research(true); } } } |
Dynamics AX: Illegal property valueIf you try to change the AllowDuplicates-Property of a table index from No to Yes, the following error message may occur: Illegal property value In this case, presumably, the affected index is registered as PrimaryIndex or ClusteredIndex of the table. |
|
|
|
|
|
|
Find below a short example, how to add object nodes to a shared project through code.
{
projectNode projectNode;
TreeNode treeNode;
#AOT
#AOTExport
projectNode = infolog.projectRootNode();
projectNode = projectNode.AOTfindChild(#expProjectShared);
projectNode = projectNode.AOTfindChild('MyProject');
// Add objects
treenode = TreeNode::findNode(#TablesPath+'\\'+tableid2name(tablenum(CustGroup)));
projectNode.addNode(treenode);
treenode = TreeNode::findNode(#TablesPath+'\\'+tableid2name(tablenum(VendGroup)));
projectNode.addNode(treenode);
treenode = TreeNode::findNode(#ClassesPath+'\\'+classStr(PriceDisc));
projectNode.addNode(treenode);
}
The so modified Project will look like this: