Thursday, June 12, 2008

Open table or browse from editor code


Many times Developer needs to open the table or browse while coding. Developer has to go to AOT then search for that table. To ease of this situation by following code developer can easily open the table or browse from Editor windows itself.

Copy paste the following methods in EditorScript Class of axapta
//------------------------
void AX_openTable(Editor e)
{

#AOT
TreeNode tr;
XInfo xInfo = new xInfo();
str selection;
;
selection= strltrim((strrtrim(Editorscripts::getSelectedText_n(e)))); // modified standard method getSelectedText
tr = TreeNode::findNode(#TablesPath + '\\'+selection);
if(tr)
tr.AOTnewWindow();
else
Throw error(strfmt("Table %1 not found",selection));

return;

}

//----------
static str getSelectedText_n(Editor e)
{
int i;
str text;
str line;
int startLine = e.selectionStartLine()+1;
int endLine = e.selectionEndLine()+1;
int startCol = e.selectionStartCol();
int endCol = e.selectionEndCol();

if (startLine == endLine && startCol == endCol)
{
e.firstLine();
while (e.moreLines())
{
text += e.getLine();
e.nextLine();
}
}
else
{
e.firstSelectedLine();
for (i = startLine; i <= endLine; i++)
{
line = e.getLine();
if (i == startLine && i == endLine)
{
line = substr(line, startcol, endCol-startCol);
}
else
if (i == endLine)
{
line = substr(line, 1, endCol-1);
}
else
if (i == startLine)
{
line = strrep(' ', startCol-1)+substr(line, startCol, strlen(line));
}

text += line;
e.nextSelectedLine();
}
}
return text;
}

//---------
To Browse the Table Add
//-------
void AX_browseTable(Editor e)
{

#AOT
TreeNode tr;
TableId TableId;
XInfo xInfo = new xInfo();
str selection;
SysTableBrowser SysTableBrowser;
;
selection= strltrim((strrtrim(Editorscripts::getSelectedText_n(e)))); // modified standard method getSelectedText
tr = TreeNode::findNode(#TablesPath + '\\'+selection);
if(tr)
{
TableId = tablename2id(selection);
if(TableId)
new SysTableBrowser().run(tableID);
}
else
Throw error(strfmt("Table %1 not found",selection));

return;

}

2 comments:

Rajdip Das said...

Excellent

Mr. Denize said...

Excellent indeed - really nice script :-D