AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
DAX
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 09.04.2009, 09:05   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
Fred Shen: X++ code to remove identical copy
Источник: http://fredshen.spaces.live.com/Blog...E4E3!258.entry
==============

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:
static void FindAndDeleteIdenticalObjects(Args _args)
{
    SysTreeNode     comparable1, comparable2;
    TreeNode          treeNode, curLevelTreeNode, upperLevelTreeNode;
    UtilIdElements    utilElements, joinUtilElements;
    str                     nodePath;
    ;

    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 joinUtilElements
            where joinUtilElements.utilLevel     !=  UtilElements.utilLevel    &&
                  joinUtilElements.name            == UtilElements.name        &&
                  joinUtilElements.recordType   == UtilElements.recordType;
        if (joinUtilElements.RecId)
        {
            switch (UtilElements.recordType)
            {
                case UtilElementType::Class:
                    nodePath = "Classes";
                    break;
                case UtilElementType::Form:
                    nodePath = "Forms";
                    break;
                case UtilElementType::Table:
                    nodePath = "Data dictionary\\Tables";
                    break;
                case UtilElementType::Enum:
                    nodePath = "Data dictionary\\Base Enums";
                    break;
                case UtilElementType::ExtendedType:
                    nodePath = "Data dictionary\\Extended Data Types";
                    break;
                case UtilElementType::Report:
                    nodePath = "Reports";
                    break;
            }
            nodePath                   = nodePath + "\\" + UtilElements.name;
            treeNode                   = TreeNode::findNode(nodePath);
            curLevelTreeNode      = treeNode.getNodeInLayer(UtilEntryLevel::var);
            upperLevelTreeNode  = SysTreeNode::getLayeredNode(treenode, 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
                treeNode.AOTdelete();
            }
       }
   }
}


Источник: http://fredshen.spaces.live.com/Blog...E4E3!258.entry
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
За это сообщение автора поблагодарили: aidsua (1), Gustav (0), shogel (1).
Теги
x++

 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
Fred Shen: Consuming a Web Service in Dynamics AX 4 Blog bot DAX Blogs 0 28.10.2006 16:40
Fred Shen: Undefined nodes in System Documentation after applying KR1 Blog bot DAX Blogs 0 28.10.2006 16:40
Fred Shen: Read and alter registry settings in Axapta Blog bot DAX Blogs 0 28.10.2006 16:40
Fred Shen: Development Features of Dynamics Ax (Axapta) 4.0 Blog bot DAX Blogs 0 28.10.2006 16:40
при построении перекрёстных ссылок выдаётся сообщение об ошибках mmmax DAX: Программирование 10 21.01.2005 12:42

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 14:58.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.