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

List all modified objects from current layer, which are not added to versioncontrol

Using the SysModel* tables, you can browse the AOT to certain objects or their properties in Dynamics AX. I've posted an example already here.

The following job is an extension of the above posting and lists all objects that have been changed in the current layer and still were not added to version control.

static void objectsNotAddedToVersionControl(Args _args)
{
    SysModelElement sysModelElement;
    SysModelElement rootModelElement;
    SysModelElementData sysModelElementData;
    TreeNodePath path;
    UtilElements utilElements;
    TreeNode treeNode;
    VersionControl vs;
    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("Objects in %1 layer, but not added to versioncontrol", 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);

    vs=new VersionControl();
    vs.init();

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

        if(vs.allowCreate(treeNode))
        {
            info(path);
        }
    }
    info("Done");

    endLengthyOperation();
}
These post applies to following version:
Dynamics AX 2012

 
 

 

 
 
 
Posts of the actual month
November 2024
MoTuWeThFrSaSu
 123
45678910
11121314151617
18192021222324
252627282930 
 
© 2006-2024 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.