Showing posts with label Ax2012. Show all posts
Showing posts with label Ax2012. Show all posts

Thursday, September 19, 2019

Parse JSON in pure X++

I decided to write a JSON parser in X++, because I couldn't find a useful implementation elsewhere. I wanted to avoid using external dll-based libraries.

It can handle strings, numbers (int and real), null-values and booleans. All kinds of linebreaks will be ignored.

It can be used like this:
str json = '{"foo": [1, 2, {"bar": 2}, {"bar": 3}]}';

AhkJSONObject ele = AhkJSONParser::parse(json);
AhkJSONArray arr = ele.get("foo");
AhkJSONObject obj = arr.get(3);
;

info('Demo 1: bar=' + obj.get("bar").strVal());
info('Demo 2: bar=' + AhkJSONParser::parse(json).getObjVal('foo').getArrayItem(3).getObjVal('bar').strVal());
info('Demo 3: bar=' + AhkJSONParser::parse(json).getObjVal('foo').getArrayItemWhere('bar', '3').getObjVal('bar').strVal());


Which will output:
Demo 1: bar=2
Demo 2: bar=2
Demo 3: bar=3

Please note the selection in demo 3, which makes it easy to select the correct array item. The project can be downloaded from the following url and is exported from AX 2009:
https://nc.ahk.dk/s/gwmTcb7N5y34SZH

The implementation is largely based on this python project:
https://github.com/eatonphil/pj/tree/master/pj

2020-01-20 update: I have updated the project with a few bugfixes, which should solve the two issues reported in comments.
2020-03-30 update: I have updated the project with a fix for parsing arrays as the outer type.

Thursday, November 13, 2014

Search Available Icons From Embedded Resources

Do you also hate looking for icons in AX when creating forms, because you need to scroll through all those images every time and they haven't even got a name to filter by?

Then I've finally got a solution for you! :)

I've made a new tool which allows you to search available image resources in AX 2012. The idea is that it traverses all form nodes and menu items for elements with icons and stores the icon resource id, label and help text. This is saved in a table, so it only needs to be done once.

When presenting this on a form, you can search for images using a text query!

Searching for "Refresh"


Download XPO

Monday, October 20, 2014

Show open windows in development view and switch between them

I just developed a simple form to show all open windows i development view. It has the following features:

  • Double-click an item to switch to the corresponding window.
  • Click "Close window" to close the selected window.
  • Auto-refreshes the view every 3 seconds.
  • Stays within the workspace (i.e. not "outside AX").
  • Stays open after switching windows (unlike the default Windows -> Windows)!
  • Works in both Dynamics AX 2009 and 2012.

It has greatly helped me manage my windows when developing...! :)

When imported, you should add a menu item pointing to the form (eg. in \Menus\GlobalToolsMenu on AX 2012).


Let me know if you need more features :)

Screenshot:



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)));
}