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)     {     ...

Dynamics AX 2012 ValidTimeState tables and form changing view from current to all

Valid Time State tables are new i AX 2012 a gives the developer the possibility to easily create tables that hold e.g. current setup data for various purposes, and at the same time keeping a "history" of the changes of the data in the table. For more reading: http://msdn.microsoft.com/en-us/library/gg861781.aspx I was tasked with doing a setup table with rates for calculating Vendor Bonus and I chose to base this a valid time state table. The customer asked for a button on the form, where you maintain the vendor bonus calculation setup data, so you could toggle viewing "Current setup" or "All setup" records (changing the view from actual to all records and vice versa in the form). I found that you can not change the ValidTimeStateAutoQuery property on the form data source in a form at run-time. It simply does not change anything, so I came up with the following solution: A boolean class member in the classdeclation method of the form: boolean ...

Subtle but important difference between _ds.executeQuery() and ds.Research()

This is actually an old entry. Been tumbling with a problem for the last few days. A form in our Dynamics AX module for Preventive Maintenance Control was not behaving. The form has "explicit" filter fields that the user can see without having to activate the form filter (CTRL+F3), for setting up filters most commonly used in an easy way. And this is working ok. However at this customer site, the form has been adjusted so that the user can have the form refreshed automatically periodically, and when the users at the customer site were making use of the "explicit" filter combined with the AX's normal filtering (CTRL+F3), the form simply threw away the normal form filtering. I discovered a subtle but very important difference between writing _ds.executeQuery(); (which was the way our code was doing it) and _ds.Research(); The difference is that _ds.Research() will retain the filter ranges in the forms query as they are right now. _ds.executeQuery() will NOT. It ...