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
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
Hey Jacob.
ReplyDeleteIn 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.
Ah.
ReplyDeleteWell 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