k3 have added custom inventory dimensions to the InventDim table, which was fine, until  we upgraded to Microsoft Dynamics AX 2012 R2.  Microsoft has introduced some new inventory dimensions for Russia and SQL Server has a limitation of 16 fields on an index.  The result being we have not been able to add the new dimensions to the index on the table, as there are now too many fields on the index to satisfy SQL Server; until we discovered a new framework that Microsoft call “Stock Dimensions Extensibility”.

I came across the following blog, which pointed me in the right direction.

http://blogs.msdn.com/b/dynamicsaxscm/archive/2012/09/11/avoid-index-length-issues-with-inventdim.aspx

Below are the steps I took to fix the issue:

1. Remove least used fields from the index.  I removed InventOwnerId_RU and InventProfileId_RU.

2. This enabled me to add the index for my new dimension without exeeding the 16 field limit.

3. On the inventDim table, in the HashKey() method, add the fields you have removed from the index (as below)

/// 
/// Calculates the string that is used when the hash value is calculated for the dimension values that
/// are not included in the DimIdx index.
/// 
/// 
/// A string that contains the calculated hash value.
/// 

public str hashKey()
{
    str     hashKey = '';

    #InventDimDevelop

    /*
    SQL Server has a limitation of 16 fields in one index. For InventDim this is a problem if extra dimensions are added in an installation.
    Instead we have added a new field which can store hashed values of the least used dimensions.
    The class InventDimUniquenessEnabling can be used to validate if the proper indexes are defined and this method includes the right fields.

    Create a string this is unique for every combination of the dimensions. This can for example be achieved by using the code pattern below for each field included in the hash.

    if (this.)
    {
        hashKey += (hashKey ? '~' : '') + ':' + this.;
    }
    */

    if (this.InventOwnerId_RU)
    {
        hashKey += (hashKey ? '~' : '') + 'InventOwnerId_RU:' + this.InventOwnerId_RU;
    }

    if (this.InventOwnerId_RU)
    {
        hashKey += (hashKey ? '~' : '') + 'InventProfileId_RU:' + this.InventProfileId_RU;
    }

    return hashKey;
}

4.   To make this work, it needs to have the  Stock Dimensions Extensibility configuration key switched on which can be found under:

System Administration –> Setup up –> Licensing –> License Configuration –> Trade –> Stock Dimensions Extensibility

5.  To make sure this configuration key was always turned on, I altered the closeOK() method on the SystemConfiguration Form as follows:

void closeOk()
{
    if (apply.enabled())
    {
        element.dialogSave();
    }

    if (apply.enabled() == false)
    {
        SysCheckList::finished(classnum(SysCheckListItem_ConfigurationKey));

        if (isConfigurationkeyEnabled(configurationKeyNum(InventDimExtensibility)))
        {
            super();
        }
        else
        {
            error("The Trade > Stock Dimension Extensibility configuration key must be enabled");
        }
    }
}

This solution should now allow you to add extra dimensions onto the InventDim table, without coming across problems concerning too many fields on the  index.