Tuesday, March 3, 2009

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.


It is applicable when you write code into an editor then select table Name (Not the buffer) and then right click -> script -> Rajdip, you will find your created menu here....




Copy paste the following methods in EditorScript Class of axapta
//------------------------

// FOR OPEN TABLE
void Rajdip_OpenTable(Editor e)
{

#AOT
TreeNode tr;
XInfo xInfo = new xInfo();
str selection;
;
selection= strltrim((strrtrim(Editorscripts::Raj_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;

}


// FOR BROWSING TABLE

void Rajdip_BrowseTable(Editor e)
{

#AOT
TreeNode tr;
TableId TableId;
XInfo xInfo = new xInfo();
str selection;
SysTableBrowser SysTableBrowser;
;
selection = strltrim((strrtrim(Editorscripts::Raj_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;

}


// FOR Selecting Text

static str Raj_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;
}



[Note: You can also open Report, EDT, Base Enum, Form by using this function with a small change i.e.
tr = TreeNode::findNode(#TablesPath + '\\'+selection);
Bold word will be changed, please follow up the "Macro->AOT", & then replace the TablePath with "ClassesPath or FormsPath, etc.]

No comments: