There appears to be a race condition when opening some forms in AX 2012 R2 when the Client performance option of "Form pre-loading enabled" is checked.
The problem seems to most readily manifest on complex forms with lots of controls that are personalized by users. In our case we discovered it with users opening LedgerJournalTransVendInvoice and LedgerJournalTransVendPaym (which incidentally we had not modified from the SYS layer at all). There were other issues with SalesTable as well.
While opening journal lines, we experienced the following error message.
DimensionDynamicAccountController object not initialized. Stack track.. \loadSegments().
This event occurs once for everyone Account number control (including Offset account number) on the form, so it is possible to see anywhere from 2 to 6 errors in the stack trace merely by opening the form.
Debugging with breakpoints shows that the loadSegments() event for each of these controls fires during the Form's init() method, and before the necessary DimensionDynamicAccountController objects have been constructed. Normally the loadSegments() method of the account number controls should not fire until the control is activated for edit. This problem even occurs when opening journal lines for posted journals, where the data source itself is not allowed for edit, and before the user has any ability to focus on a control at all.
This appears to be a race condition, since it can in some cases be highly reproducible and in others can be difficult to reproduce, even while simply opening and closing the journal lines form in quick repetition and doing nothing else. Clearing the AUC and SysLastValue for the user can bring temporary relief.
The problem appears to either require or be highly correlated to user modifications to the form, even as simple as moving a single column within the primary grid.
The problem also appears to depend upon the Form pre-loading enabled option under Client performance options being checked. Note that this option can become checked WITHOUT YOUR CONSENT, and here is how.
After upgrading to AX 2012 R2, the first time you open the SysClientPerf form the following code will run (see below). This code notices that the record is from an older configuration and AUTOMATICALLY sets the IsFormPreloadingEnabled to True as a default value. In our case, we upgraded to R2 in early March and never opened the SysClientPerf form for nearly 6 months, but immediately upon merely opening and closing the form in our production environment began to experience these issues across many users.
Hope this helps someone else.
public void EnsureSingleRecordExists()
{
/// <foundation>
#define.CurrentVersion(1)
select firstonly RecId, CurrentVersion from this;
/// </foundation>
if(!this.RecId)
{
//Default these two enum values to Yes.
this.FactBoxesEnabled = NoYes::Yes;
this.PreviewPanesEnabled = NoYes::Yes;
this.AutomaticEnhancedPreviewsEnabled = NoYes::Yes;
/// <foundation>
this.IsFormPreloadingEnabled = NoYes::Yes;
/// </foundation>
this.insert();
}
/// <foundation>
else
{
// Make sure the version number is current and perform any necessary
// upgrade steps.
if (this.CurrentVersion != #CurrentVersion)
{
ttsBegin;
select forUpdate this where this.RecId == this.RecId;
switch (this.CurrentVersion)
{
case 0:
// Enable form pre-loading by default.
this.IsFormPreloadingEnabled = NoYes::Yes;
}
this.CurrentVersion = #CurrentVersion;
this.update();
ttsCommit;
}
}
/// </foundation>
}