zoukankan      html  css  js  c++  java
  • X++ code to remove identical copy

    /***
    Our client asked for a job to remove the identical copy from VAR layer.
    For some unknown reason, some AOT objects are touched in VAR layer but actually are identical copy. When the developer compared the VAR layer object with the one in lower layer (BUS, SYS etc.), AX showed it was an identical copy.
     Here is the example on how you can remove the identical copy in X++ code:
    Wrote by Jimmy on 2010-11-12
    */

    static void Jimmy_FindAndDeleteIdenticalObjects(Args _args)
    {
        SysTreeNode         comparable1, comparable2;
        TreeNode            curLevelTreeNode, upperLevelTreeNode;
        UtilIdElements      utilElements, joinUtilElements;
    ;
        while select UtilElements
            where UtilElements.utilLevel        == UtilEntryLevel::var &&
                  (
                    UtilElements.recordType     == UtilElementType::Form        ||
                    Utilelements.recordType     == UtilElementType::Report      ||
                    Utilelements.recordType     == UtilElementType::Table       ||
                    Utilelements.recordType     == UtilElementType::Class       ||
                    Utilelements.recordType     == UtilElementType::Enum        ||
                    Utilelements.recordType     == UtilElementType::ExtendedType
                  )
        {
            //Should use join if for a normal table, but not applicable for UtilElements
            //Performance hit if use exists join
            select firstonly recid from joinUtilElements
                where joinUtilElements.utilLevel     != UtilElements.utilLevel   &&
                      joinUtilElements.name          == UtilElements.name        &&
                      joinUtilElements.recordType    == UtilElements.recordType;
            if (joinUtilElements.RecId)
            {
                //Thanks for Jim Shepherd here
                curLevelTreeNode    = SysTreeNode::findNodeInLayer(UtilElements.recordType, UtilElements.name, UtilElements.parentId, UtilElements.utilLevel);
                
                upperLevelTreeNode  = SysTreeNode::getLayeredNode(curLevelTreenode, 1);
                comparable1         = SysTreeNode::newTreeNode(curLevelTreeNode);
                comparable2         = SysTreeNode::newTreeNode(upperLevelTreeNode);
                if (SysCompare::silentCompare(comparable1, comparable2))
                {
                    info(strFmt("Element name: %1, Element type: %2", UtilElements.name, enum2str(UtilElements.recordType)));
                    //Remove the node
                    curLevelTreeNode.AOTdelete();
                }
           }
       }
    }
    //Thanks for Jim Shepherd here.   
    //http://fredshen.wordpress.com/2009/04/09/x-code-to-remove-identical-copy/
    
  • 相关阅读:
    【LeetCode】152. 乘积最大子数组(DP)
    【剑指Offer】49. 丑数(三指针)
    [P1979][NOIP2013] 华容道 (BFS建图+SPFA)
    [P1850][NOIP2016] 换教室 (期望+DP+Floyd)
    差分约束学习笔记
    [P1291][SHOI2002] 百事世界杯之旅 (期望)
    [P4342][IOI1998] Polygon (区间DP)
    [P3802] 小魔女帕琪 (期望)
    [P1273] 有线电视网 (树形DP+分组背包)
    树链剖分学习
  • 原文地址:https://www.cnblogs.com/Fandyx/p/1875637.html
Copyright © 2011-2022 走看看