Dynamics AX Blog - Dynamics AX 2012 - Microsoft Dynamics AX (Axapta) - Page 10
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 categoryRSS-Feed of this version
Creating Sysoperation classes through codeAnyone who has ever implemented a function using the SysOperation framework knows that creating the necessary (up to) four classes is some work. For In the job you have to set an "base name", which is used for naming the four classes (Controller, Dataprovider, UIBuilder and Service). In addition there is a map called dataContractParmsMap from - unless you have inserted content in this map - matching parm methods are created when generating the data provider. In example job the map contains two entries for a customer account number and an item number. |
Calling a SysOperation-based function through codeIf you need to run a function - implemented by using the SysOperation-Framework - by code, the following job can show you how you can do this. static void runSysOperationThroughCode(Args _args) { TutorialSysOperationServiceController controller; TutorialSysOperationDataContract dataContract; SysOperationStartResult sysOperationStartResult; controller = TutorialSysOperationServiceController::newFromArgs(new Args()); dataContract = controller.getDataContractObject('_dataContract'); controller.parmExecutionMode(SysOperationExecutionMode::Synchronous); dataContract.parmFilenameSave(@"c: empmyFile.txt"); dataContract.parmCustAccount('US-006'); sysOperationStartResult = controller.startOperation(); } |
Debugging SSRS-DataproviderIn the past i often had the problem, that i had to debug a dataprovider of a SSRS-Report, which could not be debugged using the well known Dynamics AX Debugger (for example because the dataprovider is executed only on server). static void testSSRSDatProvider(Args _args) { SMAWorkNoteTmp tempTable; SMAWorkNoteDP dataProvider = new SMAWorkNoteDP(); SMAWorkNoteContract contract = new SMAWorkNoteContract(); Query query = new Query(identifierStr(SMAWorkNote)); try { SysQuery::findOrCreateRange( query.dataSourceTable( tableNum(SMAServiceOrderTable)), fieldNum(SMAServiceOrderTable, ServiceOrderId)).value("00018"); contract.parmItemConsumption(true); contract.parmItemRequirement(true); contract.parmExpense(true); contract.parmFee(true); contract.parmAdditionalNotes(true); contract.parmLineText(true); if( !contract.validate()) { throw error(error::missingParameter(contract)); } dataProvider.parmDataContract(contract); dataProvider.parmQuery(query); dataProvider.processReport(); tempTable = dataProvider.getSMAWorkNoteTmp(); while select tempTable { info(tempTable.otServiceOrderId); } } catch (Exception::Break) { info("Aborted"); } } |
Add prefixes to infolog-messagesWith setPrefix () you can easily create nested messages in the infolog. static void inlinePrefix(Args _args) { setPrefix("Inhaltsverzeichnis"); info("Kapitel 1 Seite 1"); info("Kapitel 1 Seite 2"); info("Kapitel 1 Seite 3"); info("Kapitel 2 Seite 4"); info("Kapitel 2 Seite 5 Abschnitt 1"); info("Kapitel 2 Seite 5 Abschnitt 2"); info("Kapitel 2 Seite 6"); } The created infolog will look like this: |
Block journal through codeA common requirement in project life is to create journals of various types per code. JournalTableData::updateBlockServer( prodJournalTable, JournalBlockLevel::None, JournalBlockLevel::InUse, false);
|
How to create a non-primary address in global adressbookExample of how you can create a non-primary address for an entry in the global address book via code. static void createPartyAddressNonPrimary(Args _args) { DirPartyTable dirPartyTable = DirPartyTable::findByNum("???100000??"); DirParty dirParty; DirPartyPostalAddressView dirPartyPostalAddressView; // Create instance of dirParty dirParty = DirParty::constructFromCommon(dirPartyTable, DirUtility::getCurrentDateTime(), dirPartyTable.partyType()); // Create primary address dirPartyPostalAddressView.LocationName = "Delivery"; dirPartyPostalAddressView.City = "Vienna"; dirPartyPostalAddressView.Street = "Kärtnerring"; dirPartyPostalAddressView.StreetNumber = "21"; dirPartyPostalAddressView.CountryRegionId = "AUT"; dirPartyPostalAddressView.IsPrimary = NoYes::No; dirParty.createOrUpdatePostalAddress(dirPartyPostalAddressView); } |
|
|
|
|
|
|
When using the form "Security entry point permissions" the following error may occur when changing the field "Type":
The cause is that the tool tries to create an object in the AOT having the user id as part of its name. When this user ID contains characters that are not allowed in an object name (for example dashes), the error is thrown.
Simplest workaround: Using another user.