AXForum  
Go Back   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Forgotten Your Password?
Register Forum Rules FAQ Members List Today's Posts Search

 
 
Thread Tools Search this Thread Display Modes
Old 18.05.2011, 12:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,646 / 848 (80) +++++++
Join Date: 28.10.2006
axblog4u: X++ Script to renamePrimaryKey across companies
Источник: http://axblog4u.wordpress.com/2011/0...oss-companies/
==============

Hey Guys

During data upgrade to AX2012 we had issue in ‘Product Upgrade’ preprocessing checklist. Validation errors were observed due to presence of same item in different companies with different ‘DimGroupId’ or ‘ItemType’ values.

Only way left to resolve the issue was by renaming the ‘ItemId’ of these items. So we renamed all the items which are of type ‘StopItem’ to ‘%Old Item Name’.

Accordingly the String size of ‘itemIdBase’ and ‘EcoResProductNumber’ EDTs were increased to 30 to avoid the truncation of ‘ItemId’ and ‘ProductNumber’.

The best option left to optimize the work load instead of manually updating the item was to use the renamePrimaryKey method.

X++:
static void renamePKInventTable()
{
    #File
    #define.prefixItem('Old')
    InventTable     inventTable;
    container       getCompanyList;
    int             i;
    DataAreaName    id;

    container getCompany()
    {
        dataArea  dataArea;

        // Virtual Companies should not be added.
        while select dataArea
            where dataArea.isVirtual != NoYes::Yes
        {
            getCompanyList += [dataArea.id];
        }

        return getCompanyList;
    }
    ;

    getCompanyList = getCompany();

    for(i = 1; i<= conlen(getCompanyList); i++)
    {
        id = conpeek(getCompanyList, i);

        changeCompany(id)
        {
            inventTable.clear();

            while select inventTable
              where inventTable.RMCItemType == RMCItemType::StopItem
                 && inventTable.dataAreaId  == id
                 && !(inventTable.ItemId like 'Old*')
            {
                ttsbegin;

                inventTable.ItemId = #prefixItem +
                                     #delimiterSpace +
                                     inventTable.ItemId;

                inventTable.renamePrimaryKey();

                if(inventTable)
                {
                    inventTable.selectForUpdate(boolean::true);
                    inventTable.ItemName  = inventTable.ItemId;
                    inventTable.NameAlias = inventTable.ItemName;
                    inventTable.update();
                }

                ttscommit;
            }
        }
    }
}
This X++ script renamed all the Items in Item Master across companies except the virtual company;)
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.

Last edited by Poleax; 18.05.2011 at 14:01. Reason: оформление
Tags
renameprimarykey

 

Similar Threads
Thread Thread Starter Forum Replies Last Post
axblog4u: Multiple XPO Import Version – 2 Blog bot DAX Blogs 0 25.01.2011 22:11
axblog4u: Form Size Exceeds the Maximum Pixel in Dynamics AX Blog bot DAX Blogs 0 23.01.2011 10:12
mscrm4ever: CRM Form Script Loader Blog bot Dynamics CRM: Blogs 0 21.04.2009 04:07

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Рейтинг@Mail.ru
All times are GMT +3. The time now is 03:57.
Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Contacts E-mail, Advertising.