RSS

Category Archives: Models

List all modified objects from current layer


In Dynamics AX 2012, a new option has been added, and although there are now some tables that begin with SysModel*. You can also use these tables to browse the AOT objects/properties.

An example of such a query is the following job, which returns (unsorted) all objects that have been modified in the current layer.

static void objectsInCurrentLayer(Args _args)
{
SysModelElement sysModelElement;
SysModelElement rootModelElement;
SysModelElementData sysModelElementData;
TreeNodePath path;
UtilElements utilElements;
TreeNode treeNode;
Query query;
QueryRun queryRun;
QueryBuildDataSource qbds;
QueryBuildDataSource qbds1;
QueryBuildDataSource qbds2;
QueryBuildDataSource qbds3;
QueryBuildDataSource qbds4;
QueryBuildDataSource qbds5;
QueryBuildRange layerRange;
Set set = new Set(Types::String);

startLengthyOperation();

setPrefix(strFmt(“Modified objects in %1 layer”, Global::currentAOLayer()));

query = new Query();
qbds = query.addDataSource(tableNum(SysModelElement));
qbds2 = qbds.addDataSource(tableNum(SysModelElementData));
qbds3 = qbds2.addDataSource(tableNum(SysModelLayer));
qbds4 = qbds2.addDataSource(tableNum(SysModelManifest));
qbds5 = qbds.addDataSource(tableNum(SysModelElementType));

qbds2.fetchMode(QueryFetchMode::One2One);
qbds2.addLink(fieldNum(SysModelElement, RecId), fieldNum(SysModelElementData, ModelElement));

qbds3.fetchMode(QueryFetchMode::One2One);
qbds3.addLink(fieldNum(SysModelElementData, Layer), fieldNum(SysModelLayer, RecId));

qbds4.fetchMode(QueryFetchMode::One2One);
qbds4.addLink(fieldNum(SysModelElementData, ModelId), fieldNum(SysModelManifest, RecId));

qbds5.fetchMode(QueryFetchMode::One2One);
qbds5.addLink(fieldNum(SysModelElement, ElementType), fieldNum(SysModelElementType, RecId));

layerRange = SysQuery::findOrCreateRange(qbds3, fieldNum(SysModelLayer, Layer));
layerRange.value(queryValue(Global::currentAOLayer()));
layerRange.status(RangeStatus::Locked);

queryRun = new QueryRun(query);
if( !queryRun.prompt())
{
return;
}

while(queryRun.next())
{
sysModelElement = queryRun.get(tableNum(SysModelElement)) as SysModelElement;
sysModelElementData = queryRun.get(tableNum(SysModelElementData)) as SysModelElementData;

select rootModelElement
where rootModelElement.RecId == sysModelElement.RootModelElement;

utilElements = null;
utilElements.Name = rootModelElement.Name;
utilElements.ParentId = rootModelElement.ParentId;
utilElements.RecordType = rootModelElement.ElementType;
utilElements.setFieldValue(fieldStr(UtilElements, ModifiedBy), sysModelElementData.ModifiedBy);
utilElements.setFieldValue(fieldStr(UtilElements, CreatedBy), sysModelElementData.CreatedBy);

try
{
path = xUtilElements::getNodePath(utilElements);
}
catch(Exception::Warning)
{
// Continue if errors occur (for exmaple renamed objects, not written to database)
continue;
}

if (set.in(path))
{
continue;
}
set.add(path);

treeNode = xUtilElements::getNodeInTree(utilElements);

info(path);
}
info(“Done”);

endLengthyOperation();
}

 
Leave a comment

Posted by on May 26, 2015 in Models

 

Tags:

 
Dynamics Cognizance

Site presents solution to common and non-common Microsoft Dynamics Ax problems faced by Consultants and Administrators

365 by Thijs

Blogging about Microsoft 365, Azure and Automation!

axhowto

Blog about ax with sample codes, tips and tricks.

GM Dynamics Blogs

Transform IT with Digital Trasformation and Social Innovation

Ms. Dynamic Millennial

Unboxing Microsoft Dynamics 365 for Finance and Operations

DynaD365Power

Exploring the new vision of the Power platform

Dynamics Vision 365

The FinOps pulse

Breaking Bong

I write when no one is watching

ErpCoder

Microsoft Dynamics 365 Business Management Solution Enthusiast

Dynamics 365 Finance

Dynamics 365 Finance & Much More.

Microsoft Dynamics AX

“ANYONE WHO STOPS LEARNING IS OLD, WHETHER AT TWENTY OR EIGHTY.” —HENRY FORD

Sumit Potbhare

Dynamics 365 for Commerce

iotsolution.se

This is your site about D365 (Finance and Supply Chain Management), IoT (Internet of Things) and HoloLens