Dynamics AX Blog - Posts from 2015 - Page 3
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"); } } |
Congratulations on the Microsoft MVP Award 2015!...was the subject of the e-mail which reached me yesterday and informed me that I was awarded for the Microsoft MVP Award. |
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: |
AX 2012: How to change the value of a default dimension of a recordThe following job will give you an example, of how to change the value of a dimension within the default dimensions of a record (the example-job changes the value of the dimension costcenter of a customer). In this way and manner individual dimension values can be removed also. static void changeDimensionValue(Args _args) { DimensionAttributeValueSetStorage dimensionAttributeValueSetStorage; DimensionAttribute dimensionAttribute; CustTable custTable = CustTable::find("US-014"); DimensionValue oldDimensionValue; DimensionValue newDimensionValue = "011"; DimensionDefault newDimensionDefault; #define.dimensionName("CostCenter") DimensionValue getDimensonValue(DimensionDefault _dimensionDefault) { DefaultDimensionView defaultDimensionView; select firstonly DisplayValue from defaultDimensionView where defaultDimensionView.Name == #dimensionName && defaultDimensionView.DefaultDimension == _dimensionDefault; return defaultDimensionView.DisplayValue; } // Get current value oldDimensionValue = getDimensonValue(custTable.DefaultDimension); // Build DimensionAttributeValueSetStorage dimensionAttributeValueSetStorage = DimensionAttributeValueSetStorage::find(custTable.DefaultDimension); // Remove old dimension value dimensionAttribute = DimensionAttribute::findByName(#dimensionName); dimensionAttributeValueSetStorage.removeDimensionAttributeValue( DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute, oldDimensionValue).RecId); // Set new dimension value if(newDimensionValue != "") { dimensionAttribute = DimensionAttribute::findByName(#dimensionName); dimensionAttributeValueSetStorage.addItem( DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute, newDimensionValue)); } newDimensionDefault = dimensionAttributeValueSetStorage.save(); ttsbegin; custTable.selectForUpdate(true); custTable.DefaultDimension = newDimensionDefault; custTable.update(); ttscommit; } Screenshot before job Screenshot after job |
|
|
|
|
|
|
To browse the AOT for particular objects, you can use the TreeNode class. I've already posted some examples in the past.
In Dynamics AX 2012, a new option has been added, and although there are now some tables that begin with SysModel*. You can also use these tables to browse the AOT objects/properties.
An example of such a query is the following job, which returns (unsorted) all objects that have been modified in the current layer.