Dynamics AX Blog - Dynamics AX 2012 - Posts from 2015

RSS-Feed of this version
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);
} |
Open query window when opening formTo open the query-windows when opening a form, you can use the following code for example:
public void run()
{
super();
if(dataSourceName_ds.queryRun().prompt())
{
dataSourceName_ds.research();
}
}
|
Cancel salesline through codeThe code is based on the logic in the form SalesUpdateRemain ("Deliver remainder" button in the sales order header).
static void cancelSalesLine(Args _args)
{
boolean updated;
SalesLine salesLine;
try
{
ttsBegin;
salesLine = SalesLine::findInventTransId('012411', true);
updated = SalesUpdateRemain::updateDeliveryRemainder(salesLine, 0, 0);
if(updated)
{
info("Salesline canceled");
}
ttsCommit;
}
catch
{
error("SalesLine could not be canceled");
}
} |
|
|
|
|
|
|

If 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(); }