Dynamics AX Data Upgrade : Valid Time State Key Error after Upgrading or Updating

Some times during Upgrades we face a compilation error “Table does not contain a valid time state key. A unique index needs to be marked as a valid time state key.”


Cause

The index is disabled using indexAllowDup method, then properties AlternateKey and ValidTimeStateKey are reset to default value No.

ReleaseUpdateDB::indexAllowDup(new DictIndex(tableNum(TableName),
indexNum(TableName, DateEffectiveIndex)));

The error starts to show up then indexes are not enabled correctly using methodindexAllowNoDup:

ReleaseUpdateDB::indexAllowNoDup(new DictIndex(tableNum(TableName),
indexNum(TableName, DateEffectiveIndex)));

AlternateKey and ValidTimeStateKey properties are not set using the code and then you start getting compilation error mentioned above.

Solution
You should use the method indexAllowNoDupAndDateEffective instead:

ReleaseUpdateDB::indexAllowNoDupAndDateEffective(new DictIndex(tableNum(TableName),
indexNum(TableName, DateEffectiveIndex)), ValidTimeStateMode::Gap or NoGap);

Sometimes you can see the following code, but that is implemented in indexAllowNoDupAndDateEffective method:

DictIndex dictIndex = newDictIndex(tableNum(TableName),
        indexNum(TableName, DateEffectiveIndex));
    dictIndex.modify(truefalsetrue);
    dictIndex.setAlternateKey(truetrue);
    dictIndex.setValidTimeStateKey(true, ValidTimeStateMode::Gap or NoGap, true);

    appl.dbSynchronize(dictIndex.tableid(), false);

Reference:
https://community.dynamics.com/ax/b/elandaxdynamicsaxupgradesanddevelopment/archive/2015/02/12/valid-time-state-key-error-after-upgrading-or-updating

Comments

Popular posts from this blog

D365: SSRS Report Development/ Customization

D365: X++ code to add custom lookup on worker to show specific workers team workers only

Error message when you log on to a Microsoft Dynamics AX 4.0 client: "You are not a recognized user of Microsoft Dynamics AX"