CREATE ADD MODIFY AND DELETE AX x++ QUERY IN DYNAMICS AX
Static void CreateQueryJob(Args _args)
{
TreeNode treeNodeObj;
Query queryObj; // Extends TreeNode class.
QueryBuildDataSource qbds;
QueryBuildRange qbr;
QueryRun qr;
CustTable xrecCustTable;
str queryName = "MyQuery1";
// Macro.
#AOT
// Delete the query from the AOT, if the query exists.
treeNodeObj = TreeNode::findNode(#QueriesPath);
treeNodeObj = treeNodeObj.AOTfindChild(queryName);
if (treeNodeObj) { treeNodeObj.AOTdelete(); }
// Add the query to the AOT.
treeNodeObj = TreeNode::findNode(#QueriesPath);
treeNodeObj.AOTadd(queryName);
queryObj = treeNodeObj.AOTfindChild(queryName);
// Further define the query.
qbds = queryObj.addDataSource(tablenum(CustTable));
qbr = qbds.addRange(fieldnum(CustTable, DlvMode));
qbr.value(">10");
// Compile the query.
queryObj.AOTcompile(1);
queryObj.AOTsave();
// Run the query.
qr = new QueryRun("MyQuery1");
while ( qr.next() )
{
xrecCustTable = qr.GetNo(1); // 1 means first data source.
Global::info(strFmt("%1 , %2",
xrecCustTable.AccountNum, xrecCustTable.DlvMode));
}
// Delete the query from the AOT.
treeNodeObj = TreeNode::findNode(#QueriesPath);
treeNodeObj = treeNodeObj.AOTfindChild(queryName);
treeNodeObj.AOTdelete();
}
No comments:
Post a Comment