Dynamics AX Blog - Microsoft Dynamics AX (Axapta) - Page 12

In recent years, i spent a lot of time in developing in the environment of Microsoft Dynamics AX (formerly Axapta). During this time i created a lot of code, from which I could imagine, that it might be very useful for other AX developers too. But I will present also tips and tricks round the powerful ERP system.
Subscribe to RSS feed of this categoryAdd contact information for entityHere is an example of how you can add contact information data to an existing entry in the global address book. static void createPartyContactInfo(Args _args) { DirPartyTable dirPartyTable = DirPartyTable::findByNum(??"100000"); DirParty dirParty; DirPartyContactInfoView dirPartyContactInfoView; // Edit Global address book dirParty = DirParty::constructFromCommon(dirPartyTable, DirUtility::getCurrentDateTime(), DirPartyType::Organization); // Create contact info dirPartyContactInfoView.LocationName ='Office'; dirPartyContactInfoView.Locator ='+43 1 4654646'; dirPartyContactInfoView.Type = LogisticsElectronicAddressMethodType::Phone; dirPartyContactInfoView.IsPrimary = NoYes::Yes; dirParty.createOrUpdateContactInfo(dirPartyContactInfoView); } Such a created entry will look like this: |
List all modified objects from current layerTo browse the AOT for particular objects, you can use the TreeNode class. I've already posted some examples in the past. |
Create BOM through codeUsing the following code you will be able to create a BOM through code. static void createBomTableVersion(Args _args) { AxBOMTable axBOMTable; AxBOMVersion axBOMVersion; AxBOM axBOM; InventTable inventTable = InventTable::find("100160"); InventDim inventDim; try { ttsbegin; // BOM Table axBOMTable = AxBOMTable::construct(); axBOMTable.validateInput(true); axBOMTable.continueOnError(false); axBomTable.parmBOMId(BOMTable::numberSeq().num()); axBOMTable.parmItemGroupId(inventTable.itemGroupId()); axBOMTable.parmApprover(HcmWorker::userId2Worker(curUserId())); axBOMTable.parmApproved(NoYes::Yes); axBOMTable.parmName("Name of BOM"); axBOMTable.parmSiteId("GF"); axBOMTable.save(); // BOM Version inventDim.clear(); inventDim.InventSiteId = axBOMTable.parmSiteId(); inventDim = InventDim::findOrCreate(inventDim); axBOMVersion = AxBOMVersion::construct(); axBOMVersion.validateInput(true); axBOMVersion.continueOnError(false); axBOMVersion.parmBOMId(axBOMTable.parmBOMId()); axBOMVersion.parmItemId(inventTable.ItemId); axBOMVersion.parmApprover(HcmWorker::userId2Worker(curUserId())); axBOMVersion.parmApproved(NoYes::Yes); axBOMVersion.parmActive(NoYes::Yes); axBOMVersion.parmInventDimId(inventDim.InventDimId); axBOMVersion.save(); // BOM inventDim.clear(); inventDim.InventSiteId = axBOMTable.parmSiteId(); inventDim.ConfigId = "RoundNeck"; inventDim.InventSizeId = "XS"; inventDim.InventStyleId = "SlimFit"; inventDim.InventColorId = "Blue"; inventDim.InventLocationId = "902"; inventDim = InventDim::findOrCreate(inventDim); axBOM = AxBOM::construct(); axBOM.validateInput(true); axBOM.continueOnError(false); axBOM.parmBOMId(axBOMTable.parmBOMId()); axBOM.parmItemId("100158"); axBOM.parmInventDimId(inventDim.InventDimId); axBOM.parmBOMQty(17); axBOM.save(); ttscommit; } catch { throw error("BOM creation failed"); } } |
AX 2012: SysOperation-Framework: Use your own form as a dialogIn have already described how you can integrate your own form as a dialog within the SysOperation framework. Meanwhile, I've encountered a much simpler version:
protected FormName templateForm() { FormName ret; ret = formStr(CopyOfSysOperationTemplateForm); return ret; } |
Check access rights for MenuItem by codeIf you need to check the access rights of the current user for a MenuItem, the following snippet can give you an example. static void getMenuItemAccessRights(Args _args) { AccessRight accessRight = AccessRight::NoAccess; accessRight = SecurityRights::construct().menuItemAccessRight(SecurableType::MenuItemDisplay, menuitemDisplayStr(CustGroup)); info(strFmt("%1", accessRight)); } |
Open form through code and modify query of formThe following code opens form VendTable in grid and modifies the query of the form. In the example three specific vendors should be shown. static void openFormGridWithQuery(Args _args)
{ Args args; FormRun fr; QueryBuildDataSource qbds; FormDataSource fds; QueryBuildRange qbr; args = new Args(formStr(VendTable)); args.caller(null); args.menuItemType(MenuItemType::Display); args.menuItemName(menuitemDisplayStr(VendTable)); args.formViewOption(FormViewOption::Grid); fr = classfactory.formRunClass(args); fr.init(); fds = fr.dataSource(); qbds = fds.queryBuildDataSource(); qbds.addRange(fieldNum(VendTable, RecId)).value(queryValue(22565421239)); qbds.addRange(fieldNum(VendTable, RecId)).value(queryValue(22565421240)); qbds.addRange(fieldNum(VendTable, RecId)).value(queryValue(22565421714)); fr.run(); fr.detach(); } The form opened by above job may look similar to the following screenshot: |
|
|
|
|
|
|
If you need a so called AX-class can use the class AxGenerateAxBCClass.
Simply call this class in the AOT by right clicking and follow the wizard or use following job:
A that way generated class must be modified sometimes, but using the wizard is much faster than creating the class manually.
If the table changes, for example when adding new fields, you simply call that AxGenerateAxBCClass again and the AX
-class will be extended accordingly.
How to use such AX
-classes, i've described here.