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

Advertisements
 
Leave a comment

Posted by on May 26, 2015 in Models

 

Tags:

 
All About Dynamics 365

Dynamics 365, D365, Implementor

Syed Rafay Ali

This blog contains information about Functional techniques and guidelines in Microsoft Dynamics AX, including tips, tricks, tutorials, tools and upcoming news enhancement in Microsoft Dynamics Ax

Philippsen's Blog

Everyday findings in my world of .net and related stuff

Microsoft Dynamics AX

A great WordPress.com site

Finite Minds

Adventures in IoT

Dynamics Ax

Technical Knowledge

timsaxblog

A blog about implementing Microsoft Dynamics AX and Dynamics 365 for Operations

Microsoft Dynamics 365 Blog

Strat your organization's digital translation with Dynamics 365, A Blog by Sandeep Chaudhury

DEVSerra - Dynamics AX development blog

Your official Microsoft Dynamics AX blog.

OrganicAX

Discovering Dynamics

AX

A blog by Hai Nguyen

Learn Dynamics Ax with Johnkrish

Live as if you were to die tomorrow. Learn as if you were to live forever - Mahatma Gandhi ****** The more I learn, the less I know - Albert Einstein

Twisted Untwirled

Just another WordPress.com site

ramdynamicsax

Just another WordPress.com site

guyterry's Dynamics AX blog

Just another Dynamics AX blog