Hi,
I am trying to create get the voucher journal account (just like field ledgerDimension in table LedgerJournalTrans).
AX provide the standard code to do this, which is as below
acctDimAttrArray = new Array(Types::String);
acctDimAttrArray.value(1,"MainAccount");
acctDimAttrArray.value(2,"BU");
acctDimAttrArray.value(3,"Type");
acctDimAttrArray.value(4,"Section");
acctDimArray = new Array(Types::String);
acctDimArray.value(1,"123456");
acctDimArray.value(2,"AAA");
acctDimArray.value(3,"LLL");
acctDimArray.value(4,"UUU");
DefaultDimensionIntegrationValues = DimensionResolver::getEntityDisplayValue(acctDimAttrArray, acctDimArray, extendedTypeStr(DimensionDynamicAccount), LedgerJournalACType::Ledger);
DimensionDynamicAccountResolver = DimensionDynamicAccountResolver::newResolver(DefaultDimensionIntegrationValues, LedgerJournalACType::Ledger, ext());
_InsertLedgerJournalTrans.LedgerDimension = DimensionDynamicAccountResolver.resolve();
Everything looks find as it will correct ID for me. But finally, I found every time the method DimensionDynamicAccountResolver.resolve() return me a valid recId, meanwhile, it will also insert a record in a cache table. The insert method is like below,
/// <summary>
/// Adds a dimension data entity cache entry for the specified resolved value and the current resolution arguments.
/// </summary>
/// <param name="_savedRecId">
/// The resolved record ID.
/// </param>
protected void addCacheEntry(RefRecId _savedRecId)
{
DimensionDataEntitySFKCache dimensionDataEntitySFKCache;
dimensionDataEntitySFKCache.ResolvedReference = _savedRecId;
dimensionDataEntitySFKCache.IntegrationString = this.parmDimensionValues();
dimensionDataEntitySFKCache.ExtendedDataType = this.getExtendedDataTypeName();
dimensionDataEntitySFKCache.EnumValue = this.getEnumValue();
dimensionDataEntitySFKCache.EnumName = this.getEnumName();
dimensionDataEntitySFKCache.SecondaryEnumValue = this.getSecondaryEnumValue();
dimensionDataEntitySFKCache.HierarchyName = this.getDimensionHierarchyName();
dimensionDataEntitySFKCache.HierarchyType = this.getDimensionHierarchyType();
UserConnection userConnection = new UserConnection();
try
{
dimensionDataEntitySFKCache.setConnection(userConnection);
userConnection.ttsbegin();
dimensionDataEntitySFKCache.insert();
userConnection.ttscommit();
}
catch (Exception::DuplicateKeyException)
{
// The record is already cached, so just abort the transaction.
if (userConnection.ttsLevel() > 0)
{
userConnection.ttsabort();
}
}
finally
{
userConnection.finalize();
}
}
In my case, if I return the same LedgerDimension in the second time, this cache table will pop duplicate error. I just not quite understand why I do something like searching by method DimensionDynamicAccountResolver.resolve() will case record insert and even duplicate in a cache table. And how can I overcome it? Thanks!