Dynamics AX Blog - Posts from Februar 2019
These posts are machine-translated.
Post the outgoing invoice by code, selecting only certain order lines and adjusting the quantity if necessaryUsing the following code, you can post a sales invoice for a particular sales order and process only selected lines.
static void createSalesInvoiceSelectLines(Args _args)
{
SalesTable salesTable = SalesTable::find('001562');
SalesFormLetter salesFormLetter;
SalesParmLine salesParmLine;
setPrefix(funcName());
salesFormLetter = SalesFormLetter::construct(DocumentStatus::Invoice);
// Do the steps manually, which normally are done in method salesFormLetter.update()
salesFormLetter.salesTable(salesTable);
salesFormLetter.initParmSalesTable(salesFormLetter.salesTable());
salesFormLetter.transDate(systemDateGet());
salesFormLetter.specQty(SalesUpdate::All);
salesFormLetter.proforma(salesFormLetter.salesParmUpdate().Proforma);
salesFormLetter.printFormLetter(salesFormLetter.printFormLetter());
salesFormLetter.printCODLabel(NoYes::No);
salesFormLetter.printShippingLabel(NoYes::No);
salesFormLetter.usePrintManagement(false);
salesFormLetter.creditRemaining(salesFormLetter.creditRemaining());
salesFormLetter.createParmUpdateFromParmUpdateRecord(
SalesFormletterParmData::initSalesParmUpdateFormletter(
salesFormLetter.documentStatus(),
salesFormLetter.pack(),
true,
false,
false));
salesFormLetter.initParameters(salesFormLetter.salesParmUpdate(), Printout::Current);
salesFormLetter.initLinesQuery();
while select forupdate salesParmLine
where salesParmLine.ParmId == salesFormLetter.parmId()
{
setPrefix(#PrefixField(salesParmLine, InventTransId));
// ...Modify record/Delete record...
}
// Let's go
if (salesFormLetter.validate(null))
{
salesFormLetter.run();
}
}
|
|
|
|
|
|
|

The code snippets below show how to create batch jobs using the BatchHeader class.
Examples for a RunBaseBatch construct
static void createBatchWithMultipletasks(Args _args) { BatchHeader batchHeader; Tutorial_RunbaseBatch batchTask1, batchTask2, batchTask3; //create batch header batchHeader = BatchHeader::construct(); batchHeader.parmCaption("Example of a batch job with multiple tasks"); //create instances of the classes to use as batch tasks batchTask1 = Tutorial_RunbaseBatch::construct(); batchTask2 = Tutorial_RunbaseBatch::construct(); batchTask3 = Tutorial_RunbaseBatch::construct(); //add the batch tasks to the batch header batchHeader.addTask(batchTask1); batchHeader.addTask(batchTask2); batchHeader.addTask(batchTask3); //save the batch batchHeader.save(); }