Thursday, May 29, 2008

EditorScripts.addIns_OpenInAOT - version 2

A long time ago, I posted an editor script for opening objects selected in the editor in AOT (link to that post)

Yesterday, miklenew from AxForum posted an editor script for AX 3.0 that opens a new AOT window with the object currently selected in the Editor, that works a little differently and also allows to open objects based on variable type. You can view the original post here.

Today I modified this code, extending it a bit and adding support for Dynamics AX 4.0 and Dynamics AX 2009 (For version 3.0 use the code posted on AxForum).

public void addIns_OpenInAOT(Editor e)
{
#AOT
TreeNode treeNode = TreeNode::findNode(e.path());
xRefTmpReferences xRefTmpReferences;
Column nCol = e.columnNo() + 1;
Line nLine = e.currentLineNo() + 1;
;
treeNode.AOTmakeXref(1);
xRefTmpReferences = xRefCreate::makeTmp(infolog.lastxRef());

select firstonly xRefTmpReferences
order by Column desc
where xRefTmpReferences.line == nLine &&
xRefTmpReferences.Column <= nCol;

if (!xRefTmpReferences)
return;

treeNode = TreeNode::findNode(xRefTmpReferences.path());

if (treeNode)
treeNode.AOTnewWindow();
}


As you can see, the code is very simple and utilizes the xReferences.
But the great thing about it is that updating the cross references is not required for this code to work, as it updates them on the fly for this specific AOT node.
I think this is a must have method for each application developer out there. :)

1 comment:

  1. Really a nice piece of code! I modified your code a little bit according to my special needs and put it in all of our AX4-environments. Thanks a lot!

    ReplyDelete

Please don't forget to leave your contact details if you expect a reply from me. Thank you