Skip to main content

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 (http://gotdax.blogspot.dk/2012/03/dynamics-ax-2012-annoyances-for-old.html) ;-).

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)
{
    #AOT

    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;
    #define.FIELDS('\\Fields')

    if (SysContextMenu::startedFrom(_args))   // started from SysContextMenu
    {
        treeNode = _args.parmObject().first();
        _args.record(xRefPaths::find(treeNode.treeNodePath()));
    }
    else    // started with a button (or from a menu!)
    if (_args.dataset() == tablenum(UtilElements))
    {
        treeNode = xUtilElements::getNodeInTree(_args.record());
        _args.record(xRefPaths::find(treeNode.treeNodePath()));
    }
   
    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);
        }
        else
        {
            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)
            {
                for(f=1;f<=dt.fieldCnt(tableno);f++)
                {
                    df = new DictField(tableno,dt.fieldCnt2Id(f));
                    if (!df.isSystem())
                        s.add(strFmt("%1",dt.fieldName(dt.fieldCnt2Id(f))));
                }
                se = s.getEnumerator();
                while (se.moveNext())
                    fieldNameList += (fieldNameList ? "\n" : "") + se.current();

                txtb.setText(fieldNameList);
                txtb.toClipboard();
                info("Field names copied to clipboard.");
            }
        }
    }
}



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

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:

https://onedrive.live.com/redir?resid=9b63d38f981ffd1b!80242&authkey=!AH8DxBaNZUc1LTg&ithint=file%2cxpo

Comments

  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";
    Accountant_BR.insert();

    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.

    ReplyDelete
  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. :-)

    ReplyDelete

Post a Comment

Popular posts from this blog

Suppressing the infolog

Supressing the infolog is often useful in D365FO when augmenting code. When augmenting code using COC (Chain Of Command), you can have new code run either before or after the code you are augmenting. This means that any infolog-messages that the standard application code does, will be shown to the user, even if your augmentation supports a scenario where there must be no infolog-messages. How do you avoid the standard application infolog-messages ? To the rescue comes temporary supression of the infolog. The suppression consists of: 1) Saving the current infologLevel 2) Setting the infologLevel to SysInfologLevel::None 3) Run your code 4) Restoring the saved infologLevel to the infolog For example a table could have a validatewrite-method that validates that you are only allowed to use 3 out of 6 options in an enum-field, and you need to allow for a fourth one. Table a - validateWrite method: boolean validateWrite() {     Switch (this.enumField)     {         boolean ret;         case

Dynamics ax 2012 traversing selected records in a form data source

A classical developer challenge in Dynamics AX is to enable a form button when multiple records have been selected in the form by the user. This usually involves writing some form of loop (for or while or do-while) that starts out with calling _ds.getFirst() and continuing the loop as long as _ds.getNext() returns a tablebuffer. Well things got a little bit easier in AX 2012. In AX 2012 you can use the MultiSelectionHelper class. One example is the following that I encountered in AX 2012: Can you make the customer collection letter print out run for each selected collection record in the Print/Post collection letters form (Accounts receiveable / Periodic / Collections / Print/Post Collection letters). If we ignore the possibility for setting up print destination for running each report we can do this in two steps: 1) Change the "Multiselect" property of the "MenuButton" and the "Menuitembutton" in the MenuButton in the form from "Auto&quo

Indicating mandatory field in a dialog (RunBase) class.

A classical problem is indicating that a field is mandatory in a dialog, when the field is not bound to a datasource/field in a datasource. Normally fellow developers will tell you that, that is not possible. I found a way to do this. In your Runbase-based class you can implement the putToDialog-method e.g like this: protected void putToDialog() { super(); fieldMask.fieldControl().mandatory(true); } where fieldMask is a DialogField object in your dialog. This will make the field act like it was a mandatory field from a datasource in a form, showing a red-wavy line under the field, and requiring the field to have a value. Attention: Your class has to run on the client.If you set your class to run on the server, you get a run-time error, when the fieldMask.FieldControl()-call is made.