Hello AX World,
Have you ever had 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.” and could not realize where it came from? I had… many times and I did not have a clue until one day.
Such errors look strange as they show up on completely standard objects.
I have noticed that they were showing up after upgrades or updates (CUs, hot fixes etc.). That gave me a hint. I know that during an upgrade there are upgrade scripts running to enable or disable certain indexes. So I assumed that these scripts are not behaving well enough. I tried to dig it up, to find scripts that were failing and I have found the problem.
The the index is disabled using indexAllowDup method, then properties AlternateKey and ValidTimeStateKey are reset to default value No.
The error starts to show up then indexes are not enabled correctly using method indexAllowNoDup:
AlternateKey and ValidTimeStateKey properties are not set using the code and then you start getting compilation error mentioned above.
You should use the method indexAllowNoDupAndDateEffective instead:
indexNum(TableName, DateEffectiveIndex)), ValidTimeStateMode::Gap or NoGap);
Sometimes you can see the following code, but that is implemented in indexAllowNoDupAndDateEffective method:
DictIndex dictIndex = new DictIndex(tableNum(TableName),
dictIndex.modify(true, false, true);
dictIndex.setValidTimeStateKey(true, ValidTimeStateMode::Gap or NoGap, true);
I have got 3 errors after upgrading from AX 2009 to AX 2012 R3. In earlier versions I had experienced even more…
Tables that there failing:
- EximDBKValues_IN (Index: TariffCodeIdx)
- EximDEPBScheduleTable_IN (Index: ProductGroupTableRecIdx)
- PdsRebateAgreement (Index: SeqIdx)
- ReleaseUpdateDB60_Cust. allowDupEximDBKValues_IN
- ReleaseUpdateDB60_Cust. allowNoDupEximDBKValues_IN
EximDEPBScheduleTable_IN table had 2 methods as expected but index enabling was incorrect.
public void allowNoDupEximDEPBScheduleTable_INProduc()
PdsRebateAgreement table had 2 methods, the same as EximDEPBScheduleTable_IN and enabling index was incorrect.
public void allowNoDupPdsRebateAgreementSeqIdx()
I hope that helps you to save some valuable time to spend on more interesting things.