This post is machine-translated. The original post in german language can be found here.

List all modified objects from current layer

To browse the AOT for particular objects, you can use the TreeNode class. I've already posted some examples in the past.

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();
}
These post applies to following version:
Dynamics AX 2012

Add comment
 
 
 

 

 
 
 
Posts of the actual month
August 2019
MoTuWeThFrSaSu
 1234
567891011
12131415161718
19202122232425
262728293031 
 
© 2006-2019 Heinz Schweda | Imprint | Contact | German version | Mobile version
In order to provide you with better service, this site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies.