Dynamics AX Blog - Dynamics AX 2012

These posts are machine-translated.
Currently, only posts are displayed, which are relevant for Dynamics AX version »Dynamics AX 2012« Filter entfernen

RSS-Feed of this version

Create batch job with multiple tasks by code

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

 

Post the outgoing invoice by code, selecting only certain order lines and adjusting the quantity if necessary

Using the following code, you can post a sales invoice for a particular sales order and process only selected lines.
The trick is to use the standard functionality of the initLinesQuery() method to create the SalesParmLine table and modify these data records before posting. For example, by deleting entire data records from the SalesParmLine.

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

 


 

SysOperation-Framework: Simplest class construct

The code below is the simplest way to implement a function using the SysOperation framework. Without DataController, Dataprovider and UIBuilder. Only with a service class and a MenuItem.

Service

class TutorialSysOperationSimpleService extends SysOperationServiceBase
{
}

The runService() method is the actual service method. The SysEntryPointAttribute attribute controls that no further authorization checks are necessary.

[SysEntryPointAttribute(false)]
public void runService()
{
    info("Done");
}

 

SysOperation-Framework: Enable batch processing by default

If you want to activate batch processing by default for a function implemented via the SysOperation framework, you can do this by modifying the UI Builder like in the following example.

public void build()
{
    super();
    
    this.controller().batchInfo().parmBatchExecute(NoYes::Yes);
}

The code activates the checkbox Batch processing in the Batch tab.

Screenshot


 

Reading the contents of an AXMODEL file

Microsoft Dynamics AX 2012 Management ShellIf you get a hotfix from Microsoft or a module from a Microsoft partner, you often only get one or more AXMODEL files. And there is often a great desire to know in advance which objects are affected by the import of this file.

Such information can be read with the Microsoft Dynamics AX 2012 Management Shell:

Get-AXModel -File 'c:	empdynamicsax2012r3_cl4555332.axmodel' -Details

Here's how it looks:

Manifest                   Summary                    Elements
--------                   -------                    --------
Microsoft.Dynamics.AX.F... {Classes: 3}              {ClassesWHSLoadLineI...

 

Create cost center by code

If 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 table

In the following scenario, all records of a temporary table are to be passed to a SysOperation construct.

For that we need:

  • In the DataContract, a accessor method (parm-method) that takes a container
  • In the controller, a logic that iterates the records of a calling data source and packs it into a container, and passes it to the service using the above method
  • In the service class we need code, which unpacks and processed the transferred container

 

Controller

class TutorialSysOperationController extends SysOperationServiceController
{
}

 
Pages 1 2 3 4 ... 19 » 

 

 
 
 
Posts of the actual month
Februar 2019
MoDiMiDoFrSaSo
 123
45678910
11121314151617
18192021222324
25262728 
 
© 2006-2019 Heinz Schweda | Imprint | Contact | German version | Mobile version
In order to provide you with better service, this site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies.