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:

Leave a comment