torsdag den 9. april 2015

Dynamics AX 2012 AOT add-in copying field list to clip board

Before Dynamics AX 2012 and the new editor which makes things a bit more Visual Studio like, we had some features in the AOT, that are gone now but I miss.

I *might* have rambled and raved about this before ( ;-).

E.g. I miss the ability to mark all fields on a table in the AOT and simply copy them to code.
In the olds days this could be done by simply marking the fields in AOT and dragging them to the editor window.

I needed this and got fed up with having to type the field names my self so I made a little class with the main method:

public static void main(Args _args)

    DictTable   dt;
    DictField   df;
    int f,start,end;
    Set s;
    SetEnumerator se;
    int tableno;
    TextBuffer txtb = new TextBuffer();
    str fieldNameList;
    str tableName;
    TreeNode treeNode;
    str searchFor = 'Path: '+#TablesPath+#AOTDelimiter;

    if (SysContextMenu::startedFrom(_args))   // started from SysContextMenu
        treeNode = _args.parmObject().first();
    else    // started with a button (or from a menu!)
    if (_args.dataset() == tablenum(UtilElements))
        treeNode = xUtilElements::getNodeInTree(_args.record());
    if (strScan(treeNode.toString(),#TablesPath,1,1024))
        start = strScan(treeNode.toString(),searchFor,1,1024)+strLen(searchFor);
        if (strScan(treeNode.toString(),'\\Fields',1,1024))
            end = strScan(treeNode.toString(),#FIELDS,1,1024);
            end = strScan(treeNode.toString(),' Layer: ',1,1024);
        tablename = subStr(treeNode.toString(),start,end-start);
        s = new Set(Types::String);

        if (tableName)
            tableno = tableName2id(tableName);
            dt = new DictTable(tableno);
            if (dt)
                    df = new DictField(tableno,dt.fieldCnt2Id(f));
                    if (!df.isSystem())
                se = s.getEnumerator();
                while (se.moveNext())
                    fieldNameList += (fieldNameList ? "\n" : "") + se.current();

                info("Field names copied to clipboard.");

And dragged the class to the Menu Items \ Action to create the action menu item:

I then added this menu item to the SysContextMenu:

Then I can go to a table in the AOT and right click and choose add-ins / Copy field names to clipboard.

and afterwards just paste into word or excel:

I think its useful for making documentation.

You can download a private project from:!80242&authkey=!AH8DxBaNZUc1LTg&ithint=file%2cxpo

5 kommentarer:

  1. Hey Jacob.

    In AX2012, this could be done by simply marking the fields in AOT, right-clicking on them and selecting Add-Ins > Copy > Name. Then paste from the clipboard to the code editor.

    There is another useful feature. If you open a table browser, right-click in one of the field values, then "Record info", then "Script" button, and then paste from the clipboard to the code, you will see something like

    Accountant_BR.CNPJNum_BR = "";
    Accountant_BR.CPFNum_BR = "230298098-03";
    Accountant_BR.CRCCountryRegionId = "";
    Accountant_BR.CRCNum_BR = "123456789";
    Accountant_BR.CRCStateId = "";
    Accountant_BR.Name = "Joao Silva";

    You could also paste this to Excel, then split to columns (using "." and "=" symbols as delimiters) and get the list of fields in the second column.

  2. Ah.
    Well at least I had fun making my version -
    which also has the advantage of getting the field names regardless of the cursor being situated at the tablename it self or any subnode and one less submenu to choose from. :-)

  3. Interesting article, it was nice to visit your site. The way of presentation is well. Thanks for sharing!!
    MS Power BI Online Training