Dynamics AX Blog - Posts from 2018
Create cost center by codeIf you are ever embarrassed to have to create a cost center by code, this job may serve as inspiration: static void createCostCenter(Args _args) { str 30 _costCenter = "0815"; // Cost center id to create OMOperatingUnit omOperatingUnit; NumberSeqFormHandler numberSeqFormHandler; NumberSeq numberSeq; if (_costCenter) { if (!OMOperatingUnit::findName( _costCenter, OMOperatingUnitType::OMCostCenter)) { ttsbegin; numberSeq = NumberSeq::newGetNumFromId( OMOperatingUnit::getNumberSequenceReference().NumberSequenceId); omOperatingUnit.clear(); omOperatingUnit.initValue(); omOperatingUnit.omOperatingUnitNumber = numberSeq.num(); omOperatingUnit.Name = _costCenter; // Id used as name omOperatingUnit.NameAlias = _costCenter; omOperatingUnit.omOperatingUnitType = OMOperatingUnitType::OMCostCenter; omOperatingUnit.LanguageId = CompanyInfo::languageId(); if (omOperatingUnit.validateWrite()) { omOperatingUnit.insert(); } ttscommit; } } } |
SysOperation framework: Pass selected records from a temporary tableIn the following scenario, all records of a temporary table are to be passed to a SysOperation construct. For that we need:
Controllerclass TutorialSysOperationController extends SysOperationServiceController { } |
Enter price information on order lines through code and control price searchA common requirement in projects is that sales order lines should be created by code, such as data imports or similar. Recently I had the request that code-generated sales order lines are then to be processed manually, but the price information such as sales price and rebate should be preserved. However, editing certain fields in a sales order line in Dynamics AX triggers price search. This had to be prevented or pointed out to the user at least by a query. Fortunately, there is already one such query, which is controlled by the following fields:
| ||||||||
Split a string with fixed separatorsThe following snippets are meant to show how to extract the individual elements from a string with fixed separators. Variant 1: Convert the string to a container using str2con() static void Job1(Args _args) { str paramAsStr = "Wert1@@Wert2@@Wert3"; container paramAsCon; int i; paramAsCon = str2con(paramAsStr, "@@"); for (i=1;i<=conLen(paramAsCon);i++) { info(conPeek(paramAsCon, i)); } }
static void Job1(Args _args) { str paramAsStr = "Value 1|Value 2|Value 3"; List paramAsList; ListEnumerator le; paramAsList = strSplit(paramAsStr, "|"); le = paramAsList.getEnumerator(); while(le.moveNext()) { info(le.current()); } }
|
Create waves for one or multiple deliveriesThe following snippet shows how to build waves and work for one ore more delivery through code. This will usually happen if you use the "Release to warehouse" function. WHSWaveTable::buildWaveFromShipments(['USMF-000006','USMF-000007']); |
|
|
|
|
|
|
Such information can be read with the Microsoft Dynamics AX 2012 Management Shell:
Here's how it looks: