Thursday, September 1, 2011

Ax 2012 - Get dimensions

If you've been working with Dynamics AX 2012 dimensions, you'll know that they are pretty hard to understand and work until you get to know them. I finally figured out how to get the dimensions and dimension values through X++.

Get dimensions:

DimensionAttribute              dimAttr;
DimensionAttributeSetItem       dimAttrSetItem;
DimensionAttributeSetItem       dimAttrSetItemEditable;
DimensionEnumeration            dimensionSetId;
dimensionSetId = DimensionCache::getDimensionAttributeSetForLedger();
while select dimAttr
    order by Name
       where dimAttr.Type != DimensionAttributeType::MainAccount
        join RecId from dimAttrSetItem
       where dimAttrSetItem.DimensionAttribute == dimAttr.RecId &&
             dimAttrSetItem.DimensionAttributeSet == dimensionSetId
  outer join RecId from dimAttrSetItemEditable
       where !dimAttrSetItemEditable.DimensionAttributeSet &&
             dimAttrSetItemEditable.DimensionAttribute == dimAttr.RecId &&
             dimAttrSetItemEditable.EnumerationValue == NoYes::Yes
{
   info(dimAttr.Name);
}
Get dimension values for the "CostCenter" dimension:
Common common;
DimensionAttribute dimAttr;
select firstOnly dimAttr where dimAttr.Name == "CostCenter";
common = new DictTable(dimAttr.BackingEntityType).makeRecord();
while select common
{
    info(strFmt("%1", common.(dimAttr.NameAttribute)));
}

Wednesday, August 31, 2011

Dynamic lookup on forms


To create a custom dynamic lookup on a form, override the lookup method on the control, and add the following code. This code allows you to select a year, but it should be clear what you need to modify to show something else:

public void lookup()
{
    Counter yearCount;
    List    valueList = new List(Types::String);

    for (yearCount = 0; yearCount < 5; yearCount++)
    {
        valueList.addEnd(strFmt("Year %1", year(SystemDateGet()) - yearCount));
    }

    SysLookup::lookupList(this, valueList, "List of years");
}

Show temporary table content


Run the following and you will be able to see the contents of a temporary table during runtime, which I find very helpful when debugging:

new SysTableBrowser().run(tmpTable.TableId, tmpTable);

To get it running, you need to overwrite the run method on SysTableBrowser with a new parameter profile:
public void run(tableId tableId, common tmpBuffer = null)
 and add the following line before formRun.run();
if (tmpBuffer.TableId < 60535)
    formRun.parmTmpData(tmpBuffer);

Overwrite license on Dynamics AX 4.0

My first post is regarding an issue I had a couple of weeks back, where AX crashed when overwriting an expired license with a new one (AX 4.0), which resulted in a broken database. After a lot of problems and not working solutions, I finally solved it, and of course I'll share the solution with you guys:
  1. Connect to the database and delete the content of the VALUE field of the first three lines in the SYSCONFIG table
  2. Stop the AOS service
  3. Delete the .aoi file in the appl directory
  4. Run "dir *.auc/s" on the client (deletes all cache files on the computer - you need to be on the drive of your Windows installation)
  5. If it detects any files, run "del *.auc/s" which deletes them.
  6. Start the AOS service
  7. Start the client and import licence again. Accept the synchronization
  8. If AX crashes again during import, do steps 2-6 again and it will work! :)
I've solved this problem successfully on several installations using the approach above, so try it! :)

Regards,
Anders