Home > X++ stuffs > X++ Script to renamePrimaryKey across companies

X++ Script to renamePrimaryKey across 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.

static void renamePKInventTable()
    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);


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

                inventTable.ItemId = #prefixItem +
                                     #delimiterSpace +

                    inventTable.ItemName  = inventTable.ItemId;
                    inventTable.NameAlias = inventTable.ItemName;


This X++ script renamed all the Items in Item Master across companies except the virtual company;)

Categories: X++ stuffs
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: