Only 2 clicks to get help on how to use functions with example [In Editor]

This post will be very helpful for the developers who are new and are looking for an example on how to use a functions with an example . Usually any developer who is very new to Dynamics AX will go to AOT >> System Documentation >> functions and will select a function >> right clicks and use edit option to get help on the function and example if any.

Well, I know its very boring way to go always to that level and get help. I have modified Editorscripts class again to get quick help in the editor itself.

All you need to do is add the below method “ShowExample” to the EditorScripts class

public void ShowExample(Editor editor)
{
str line;
int i;
int startLine = editor.selectionStartLine();
int endLine = editor.selectionEndLine();
int startCol = editor.selectionStartCol(); //points at the first selected char
int endCol = editor.selectionEndCol()-1; //points at the last selected char
MarkMode markMode = editor.markMode();
#define.maxLineLength(300)
#AOT

Form formBrowse;
FormHTMLControl htmlControl;
FormRun formRun;
Args args;
str htmlContent;
TreeNode functionTreeNode;
Editor _editor = editor;
str h1Tag;
void transform(str _function)
{

;

functionTreeNode = TreeNode::findNode(#SystemFunctionsPath+’\\’+_function);
if (!functionTreeNode)
throw error (“Function not found in System documentation”);
formBrowse = new Form(‘Function Example’, true);
formBrowse.design().caption(_function + ” Example”);
formBrowse.design().width(700);
formBrowse.design().height(500);
formBrowse.design().addControl(FormControlType::HTML, ‘html’);
args = new Args(formBrowse.name());
args.name(formBrowse.name());
args.object(formBrowse);
formRun = classFactory.formRunClass(args);
formRun.init();
htmlControl = formRun.design().controlName(‘html’);
htmlControl.height(1,1);
htmlControl.width(1,1);
formRun.run();

htmlControl.setText(functionTreeNode.AOTgetSource());
formRun.detach();
}

void transformLine(int lineNo, int start, int end)
{
_editor.gotoCol(0);
_editor.gotoLine(lineNo);
line = _editor.currentLine();

transform(substr(line, start, end-start+1)) ;

return;
}
;
editor.unmark();

switch (markMode)
{
case MarkMode::LineMark:
editor.gotoCol(1);
for (i=startLine; i<=endLine; i++)
{
transformLine(i, 1, #maxLineLength);
}
break;

case MarkMode::ColMark:
for (i=startLine; i<=endLine; i++)
{
transformLine(i, startCol, endCol);
}
break;

case MarkMode::AreaMark:
if (startLine == endLine)
{
transformLine(startLine, startCol, endCol);
}
else
{
//convert first line
transformLine(startLine, startCol, #maxLineLength);

//convert full lines
for (i=startLine+1; i<endLine; i++)
{
transformLine(i, 1, #maxLineLength);
}

//convert last line
transformLine(endLine, 1, endCol);
}
break;
}
}

Wondering how to use it now.
Create a new job and write any function. In the below example I have shown this by using strfmt function. Double click the function and select scripts button>> Show example as shown below

There you go. you will get help on how to use this function with an example on your screen. Isn’t it helpful?? Below is the output form which gives you quick help on the functions. You can get the help for any function which is defined in system documentation.

Advertisements

3 Clicks to generate AXBC code

As we all know AXBC’s are used by external applications to talk to AX and access/invoke business logic to do some DML operations with the tables in AX. AIF Framework uses internally these classes to do these service operations.

However, these classes can also be used within AX to do the CRUD operations. This post will help to easily create/generate code on how to use AXBC classes or call the methods in these classes to insert the data. This logic will be given to the outside application development team to quickly help them to understand and call AXBC classes [Specially from .net applications]

Follow or customize the form [SysRecordInfo] as shown below and start generating AXBC codes easily.

Go to AOT >> Forms >> SysRecordInfo and add a new button with name GenerateCode as shown below

Now, right click on the newly created button , Go to properties and rename the button label as Generate AXBC Code as shown below

Create a new method on the form as shown below

void buildAXBCCode()
{
str createAXBCStr;
str axbc;
SysDictClass sysDictClass;
SysDictMethod sysDictMethod;
int methodCount;
str 100 methodName;
str argumentValue;
TreeNode treeNode, classTreeNode, tableNode;
str classObjName;
str jobName;

str bufferName;
str 100 fieldName;
int i;
#define.tab(‘ ‘)
#define.semicolon(‘;’)
#define.Ax(‘Ax’)
#define.parm(‘parm’)
#AOT

str convertToCapital(str _word)
{
str 1 firstAlphabet;
str tmpWord;
;
firstAlphabet = strlwr(substr(_word, 1,1));
tmpWord = strdel(_word,1,1);
tmpWord = firstAlphabet + tmpWord;

return tmpWord;
}
;
axbc = #Ax +dictTable.name();

classtreeNode = TreeNode::findNode(#ClassesPath);

tableNode = TreeNode::findNode(#TablesPath+’\\’+dictTable.name()+’\\Fields’);

if (!classtreeNode.AOTfindChild(axbc))
{
throw error(strfmt(“AXBC with name %1 not available in classes”, axbc));
}

treeNode = TreeNode::findNode(#JobsPath);
jobName = ‘Example_’+axbc+’_job’;

if (!treeNode.AOTfindChild(jobName))
{
treeNode = treeNode.AOTadd(jobName);
}

createAXBCStr += ‘static void ‘+ jobName + ‘(Args _args)\n{\n’;

bufferName = convertToCapital(dictTable.name());
classObjName = convertToCapital(axbc);

createAXBCStr += #tab + dictTable.name() + #tab + bufferName ;
createAXBCStr += #semicolon + ‘\n’;

createAXBCStr += #tab + axbc + #tab + classObjName + #tab + ‘=’ + #tab + axbc +’::newValidateInput();\n’ + #tab + #semicolon +’\n’;
createAXBCStr += #tab + ‘ttsbegin;\n’;

sysDictClass = new SysDictClass(className2Id(axbc));
methodCount = sysDictClass.objectMethodCnt() ;
for(i = 1 ; i <= methodCount ; i++)
{
sysDictMethod = sysDictClass.objectMethodObject(i);
methodName = sysDictMethod.name();
if (strstartswith(methodName,#parm))
{
fieldName = strdel(methodName,1,4);
if (tableNode.AOTfindChild(fieldName))
{
createAXBCStr += #tab + classObjName+'.'+fieldName +'('+bufferName+'.'+methodName+');\n';
}
else
{
createAXBCStr += #tab + classObjName+'.'+fieldName +'('+bufferName+'.'+methodName+'());\n';
}
}
}
createAXBCStr += #tab + 'ttscommit;\n';
treeNode.AOTsetSource(createAXBCStr + '}');
treeNode.AOTcompile(1);
treeNode.AOTsave();
treeNode.AOTnewWindow();
treeNode.AOTedit();
}

Next Override the clicked method of the button and call the newly created method as shown below

void clicked()
{
element.buildAXBCCode();
}

How to generate AXBC code is show below

Open Customers form from AR>> Customer details. Right click on the Grid and select the option RecordInfo as shown below.

Once you click on RecordInfo option >> you will find a new button Genrate AXBC Code on the form as shown below

Click on the Generate AXBC Code button to generate the code. This will create a new runtime Job and will be seen on the screen as shown below [Note name of the job will be – Example_AXTableName_Job
Output: