Monday, April 26, 2010

Open any object from code editor to in AOT node(Editor script)


I have posted a editor script method earlier that can open and browse table for code editor.using below code developer will have ease of opening any object from AX code editor to AOT node

TO USE THIS CODE COPY AND PASTE THE METHOD IN EDITOR SCRIPT CLASS

void AX_OpenInAOT(Editor e)
{
#AOT
TreeNode treeNode;
FreeText selectedLine;
str 1 curSymbol;
int iCopyFrom;
int iCopyTo;
Set selectedNodesSet = new Set(Types::Class);
SetIterator setIterator;
Map map;

void add2Set(TreeNodePath _path)
{
;
treeNode = TreeNode::findNode(_path + #AOTRootPath + selectedLine);
if (treeNode)
selectedNodesSet.add(treeNode);
}
;
if (e.markMode() != MarkMode::NoMark && e.selectionStartCol() != e.selectionEndCol())
{
selectedLine = strLRTrim(subStr(e.currentLine(), e.selectionStartCol(), e.selectionEndCol() - e.selectionStartCol()));
}
else
{
selectedLine = e.currentLine();
for (iCopyFrom = e.columnNo()+1; iCopyFrom >= 0; iCopyFrom--)
{
curSymbol = subStr(selectedLine, iCopyFrom, 1);
if (!strAlpha(curSymbol))
break;
}
for (iCopyTo = e.columnNo()+1; iCopyTo <= strLen(selectedLine); iCopyTo++) { curSymbol = subStr(selectedLine, iCopyTo, 1); if (!strAlpha(curSymbol)) break; } selectedLine = (iCopyFrom <> 0)
{
setIterator = new SetIterator(selectedNodesSet);
setIterator.begin();
if (selectedNodesSet.elements() == 1)
{
treeNode = setIterator.value();
}
else
{
map = new Map(Types::String, Types::String);
while (setIterator.more ())
{
treeNode = setIterator.value();
map.insert(treeNode.treeNodePath(), treeNode.AOTparent().treeNodeName());
setIterator.next();
}
treeNode = TreeNode::findNode(pickList(map, "Location", "Select element type"));
}
if (treeNode && treeNode.treeNodePath() != TreeNode::rootNode().treeNodePath())
{
if (SysTreeNode::hasSource(treeNode))
{
if (treeNode.AOTparent().treeNodePath() == #macrosPath && subStr(e.currentLine(), e.selectionStartCol () - 1, 1) != '#')
return;
treeNode.AOTedit();
}
else
{
treeNode.AOTnewWindow();
}
}
}
}
}

String function class

While working on string function i have found an nice code on Greg Pierce's blog extending existing AX string function functionality to construct newer method above post is in AX 3.0 and 4.0 below code is in AX 2009

COPY PASTE THE CODE IN NOTE PAD AND SAVE AS XPO.

Exportfile for AOT version 1.0 or later
Formatversion: 1

***Element: CLS

; Microsoft Dynamics AX Class: String_Func unloaded
; --------------------------------------------------------------------------------
CLSVERSION 1

CLASS #String_Func
Id 30211
PROPERTIES
Name #String_Func
Extends #
RunOn #Called from
ENDPROPERTIES

METHODS
Version: 3
SOURCE #trimToLength
#/* trim a string to a length, optionally add ellipsis if string is truncated.*/
#public static str trimToLength( str _s, int _length, str _trimStr = "" )
#{
# str s;
#
# if( strlen( _s ) < s =" strdel(" exceptions =" [" fl =" true;" s =" strltrim(" ix =" 1;" s1 =" strdel(" s1 =" strdel(" fl =" true;" s =" strpoke(" s =" strpoke(" fl =" false;" pos =" strscan(" fname =" strdel(" lastname =" strdel(" s =" _s," pos =" 1," loc =" strscan(" loc ="=" c =" conins("> 0 )
# {
# _value = strdel( s, loc, strlen(s) - loc + 1 );
#
# if( _value && _value != _delimeter )
# {
# c = conins( c, pos, _value );
# pos++;
# }
# s = strdel( s, 1, loc );
#
# loc = strscan( s, _delimeter, 1, strlen( s ) );
# }
# if( s && s != _delimeter )
# c = conins( c, pos, s );
#
# return c;
#
#}
ENDSOURCE
SOURCE #rSplit
#/* split item of right of string, trimmed at delimiter*/
#static str rSplit( str _s, str _delimeter )
#
#{
# str s = "";
# int pos;
# int len = strlen( _s );
#
# pos = strfind( _s, _delimeter, len, -len );
# s = strdel( _s, 0, pos );
#
#
# return s;
#}
ENDSOURCE
SOURCE #replaceAll
#/* replace the all occurances of "findStr" with "replStr" in "s"*/
#
# static str replaceAll( str s, str findStr, str replStr )
# {
# int pos = strscan( s, findStr, 1, strlen( s ) );
#
# while( pos > 0 )
#
# {
# s = strdel( s, pos, strlen( findStr ) );
# s = strins( s, replStr, pos );
#
# pos = strscan( s, findStr, pos + strlen( replStr ), strlen( s ) );
#
# }
#
# return s;
# }
ENDSOURCE
SOURCE #replace
#/* replace the first occurance of "findStr" with "replStr" in "s"*/
#
#static str replace( str s, str findStr, str replStr )
#
#{
# int pos = strscan( s, findStr, 1, strlen( s ) );
#
# if( pos > 0 )
# {
# s = strdel( s, pos, strlen( findStr ) );
# s = strins( s, replStr, pos );
#
# }
#
# return s;
#}
ENDSOURCE
SOURCE #randomString
#/* build a random string of length passed*/
#public static str randomString( int _length = 6 )
#{
# str s;
# int ix = 0;
# str nxt;
# RandomGenerate random = new RandomGenerate();
# ;
#
# for( ix = 0; ix < nxt =" int2str(" random =" new" s = ""> " + ( String_Func::beginsWith( "abcdef", "abc" ) ? "true" : "false" ) );
#
#
# info( "String_Func::endsWith( \"abcdef\", \"def\" ) -> " + ( String_Func::endsWith( "abcdef", "def" ) ? "true" : "false" ) );
#
#
# info( "String_Func::fillString( 10, \"a\" ) -> " + String_Func::fillString( 10, "a" ) );
#
# info( "String_Func::replace( \"abc123abc123\", \"abc\", \"def\" ) -> " + String_Func::replace( "abc123abc123", "abc", "def" ) );
#
#
# info( "String_Func::replaceAll( \"abc123abc123\", \"abc\", \"def\" ) -> " + String_Func::replaceAll( "abc123abc123", "abc", "def" ) );
#
#
# info( "String_Func::randomString( 8 ) -> " + String_Func::randomString() );
#
# info( "String_Func::rSplit( \"abc|def\", \"|\" ) -> " + String_Func::rSplit( "abc|def", "|" ) );
#
#
#}
ENDSOURCE
SOURCE #fillString
#/* build a repeating string of length ct
# */
#
#public static str fillString( int ct, str char = " " )
#
#{
# int ix;
# str s = "";
# ;
#
# for( ix = 0; ix < trim =" strdel(" trim ="="> 0 )
# return true;
#
# return false;
#
# }
ENDSOURCE
SOURCE #cleanString
#/* use to do multiple string manipulations on the string passed, including case forcing and substitutions */
#
# static str cleanString( str s, container forceLower, container forceUpper, container subst, boolean flFixDoubleSpaces = true )
# {
# int ix;
#
#
# // FIX LOWER CASE LIST
# for( ix = 1; ix <= conlen( forceLower ); ix++ )
# {
# s = String_Func::replaceAll( s, conpeek( forceLower, ix ), strlwr( conpeek( forceLower, ix ) ) );
#
# }
#
# // FIX UPPER CASE LIST
# for( ix = 1; ix <= conlen( forceUpper ); ix++ )
# {
# s = String_Func::replaceAll( s, conpeek( forceUpper, ix ), strupr( conpeek( forceUpper, ix ) ) );
#
# }
#
# // DO SUBSTITUTIONS
# for( ix = 1; ix <= conlen( subst ); ix++ )
# {
# s = String_Func::replaceAll( s, conpeek( conpeek( subst, ix ), 1 ), conpeek( conpeek( subst, ix ), 2 ) );
#
# }
#
# // FIX double spaces
# if( flFixDoubleSpaces )
# {
# while( String_Func::contains( s, " " ) )
# {
# s = String_Func::replaceAll( s, " ", " " );
#
# }
# }
#
# return s;
#
# }
ENDSOURCE
SOURCE #beginsWith
#/*return true if "findStr" is the inital character match for "s" */
#
# static boolean beginsWith( str s, str findStr )
#
# {
# if( strscan( s, findStr, 1, strlen( s ) ) == 1 )
# return true;
#
# return false;
# }
ENDSOURCE
SOURCE #classDeclaration
#public class String_Func
#{
#}
ENDSOURCE
ENDMETHODS
ENDCLASS

***Element: END