Version control through Job

Hi,

I need to create a job to add tables to version control

1) iterate through all tables

2) check if it is in USR layer

3) If the table is in USR layer, then add it to version control

Is there any way to do through x++.

Thanks in advance

  • Hello,

    You can use the following job to iterate elements that are not added in version control,

    static void ObjectsNotInVCS(Args _args)
    {
        #SysVersionControl
        #AviFiles
    
        SysVersionControlSystem vcsSys = versionControl.parmSysVersionControlSystem();
        SysVersionControllable  controlable;
    
        UtilEntryLevel  curLayer    = currentAOLayer();
        modelId         curModelId  = xInfo::getCurrentModelId();
    
        SysModelElementData elemData, parentData;
        SysModelElement     parent, child;
        TreeNode            pNode, cNode;
        SysOperationProgress progress;
    
        Map treeNodePathMap = new Map(Types::String, Types::String);
        MapEnumerator mapEnumerator;
    
        setPrefix(strFmt('%1\tModel: %2',
                         funcName(),
                         SysModelStore::modelId2Name(curModelId)));
    
        //Set options to skip cache lookup of file names
        infolog.globalCache().set(#VCSCache, #NoPrompt, true);
    
        progress = SysOperationProgress::newGeneral(#AviSearch, funcName(), -1);
        startLengthyOperation();
    
        while select RootModelElement from child
            group by child.RootModelElement, elemData.ModelId
            join ModelId
                from elemData
                where ((elemData.ModelElement == child.RecId) &&
                       (elemData.Layer == (curLayer + 1)) &&    // Layer numbers in SysModel* views are offset by +1
                       (elemData.ModelId == curModelId))        // Remove the following line to include all models
        {
            progress.incCount();
    
            //Get lowest layer copy of parent
            select firstOnly parent
                order by parentData.Layer
                    where (parent.RecId == child.RootModelElement)
                join parentData
                    where ((parentData.ModelElement == parent.RecId) &&
                           (parentData.ModelId == curModeLid));
    
            pNode = SysTreeNode::findNodeInLayer(
                          parent.ElementType, parent.name, 0, parentData.Layer - 1);
            if (!pNode)
            {
                continue;
            }
    
            progress.setText(pNode.treeNodePath());
    
            controlable = SysTreeNode::newTreeNode(pNode);
            if (!controlable)
            {
                continue;
            }
    
            if (vcsSys.allowCreate(controlable) &&
                vcsSys.allowCheckOut(controlable) &&
                !SysTreeNode::isUnwanted(pNode))
            {
                treeNodePathMap.insert(pNode.treeNodePath(), parentData.modifiedBy);
            }
        }
    
        mapEnumerator = treeNodePathMap.getEnumerator();
        while (mapEnumerator.moveNext())
        {
            if (mapEnumerator.currentValue() == curUserId())
            {
                error(strFmt('Modified by %1\t%2',
                             curUserId(),
                             mapEnumerator.currentKey()));
            }
        }
        mapEnumerator.reset();
        while (mapEnumerator.moveNext())
        {
            if (mapEnumerator.currentValue() != curUserId())
            {
                warning(strFmt('Modified by other users\t%1 (%2)',
                               mapEnumerator.currentKey(),
                               mapEnumerator.currentValue()));
            }
        }
    
        endLengthyOperation();
    
        info("Done");
    }

    Thanks.

  • In reply to Wekey:

     

    Thanks for your reply.

    When i compiled the job it showing syntax error.

  • In reply to Ilamvazhudhi Sri Ranjani:

    Is it for ax 2009?
    I want only the usr layer tables to be added to version control.
  • In reply to Ilamvazhudhi Sri Ranjani:

    Try like this..
    SysVersionControlSystem vcsSys;
    vcsSys = versionControl.parmSysVersionControlSystem();
  • In reply to Ilamvazhudhi Sri Ranjani:

    Hello,

    Sorry my mistake. I didnt see the tag properly. However I hope the code works well with 2009 too, I dont have 2009 environment to check from my side.
  • In reply to Gopinath M:

    It still showing syntax error..
  • In reply to Wekey:

    static void ListUsrTables(Args _args)
    {
    UtilElements utilElements;

    while select utilElements
    where utilElements.utilLevel == UtilEntryLevel::usr
    && utilElements.recordType == UtilElementType::Table
    {
    // Do your work here
    print strFmt("%1 : %2",utilElements.recordType,utilElements.name);
    }
    }

    this shows usr layer tables, but how should i add version control to tat tables?
  • In reply to Ilamvazhudhi Sri Ranjani:

    U tried the following code?

    if(vcsSys.allowCreate(controlable))
    {
    //sysTreeNode is of type SysTreeNode
    sysTreeNode = sysTreeNode::construct();
    sysTreeNode.parmTreeNode(pNode);
    if(sysTreeNode.canCreate() == true)
    {
    //do something if it isn't in version control
    info(strfmt("%1 %2",pNode.treeNodePath(), modelName));
    vcsSys.commandAdd(controlable); //SHS add to version control
    }
    }
  • In reply to Wekey:

    Modify the code as per your requirement

    Thanks
  • In reply to Wekey:

    community.dynamics.com/.../ax-2012-add-elements-to-version-control
    blog.slcconsulting.us/.../


    I tried using those blogs, but still i cant get the desired result...

    Note: modelid isn't available in ax 2009.

    So where could i change my coding to get the output?
  • In reply to Ilamvazhudhi Sri Ranjani:

    static void versionctrl(Args _args)
    {
    SysVersionControlSystem vcsSys;
    SysVersionControllable controllable;
    
    UtilElements UtilElementsLocal,parent;
    TreeNode treenode;
    ;
    
    vcsSys = versionControl.parmSysVersionControlSystem();
    
    if(!vcsSys)
    {
    info("Version control not enabled");
    return;
    }
    
    while select * from UtilElementsLocal
    where UtilElementsLocal.recordType == UtilElementType::Table
    && UtilElementsLocal.utilLevel == global::currentAOLayer()
    {
    
    parent=xUtilElements::parentElement(UtilElementsLocal);
    
    treenode=SysTreeNode::findNodeInLayer(parent.recordType, parent.name, 0, curLayer);
    
    if(!treenode)
    continue;
    controllable = SysTreeNode::newTreeNode(treeNode);
    if(!controllable)
    continue;
    
    if(vcsSys.allowCreate(controllable))
    {
    
    vcsSys.commandAdd(controllable);
    }
    }
    }

     

    I tried to do by above job, when I'm running for the first time it added the user layer tables to version control after that I did checkin to those tables manually.

    Now when i tried to run the job again to add the tables, its not working correctly.

    Is there any error?

    Thanks in advance.

  • In reply to Ilamvazhudhi Sri Ranjani:

    You must realize that we can't help you if you don't explain your problem. Please tell us what you mean by "its not working correctly" in this particular case.
    Note that nothing will be added if all eligible tables have already been added.
Related
Recommended