Sunday, August 19, 2012

AX 2012 : Delete All Transactions


Hi,
    Today we will look at, How to delete all transactions from AX 2012. Previously we were using SysDatabaseTransDelete class to do the same but as of now we need to modify that class to work properly with AX 2012 due to DB changes :


We need to modify the SysDatabaseTransDelete.handletable method with the below code :

void handleTable(SysDictTable sysDictTable)
{
    TableGroup      tableGroup;

    if (tableSet.in(sysDictTable.id()))
        return;
    tableSet.add(sysDictTable.id());

    if (sysDictTable && !sysDictTable.isTmp() && !sysDictTable.isMap())
    {
        tableGroup = sysDictTable.tableGroup();

        // Handle company specific tables to be deleted
        if (sysDictTable.dataPrCompany())
        {
            switch(tableGroup)
            {
                case TableGroup::Transaction:
                case TableGroup::WorksheetHeader:
                case TableGroup::WorksheetLine:
                //FIX - Support new AX2012 transaction table types
                case TableGroup::TransactionHeader:
                case TableGroup::TransactionLine:
                    this.handleTransTable(sysDictTable);
                    break;
                default:
                    this.handleNonTransTable(sysDictTable);
                    break;
            }
        }
        else
        {
            // Handle global tables to be deleted
            switch(tableGroup)
            {
                case TableGroup::Transaction:
                case TableGroup::WorksheetHeader:
                case TableGroup::WorksheetLine:
                //FIX - Support new AX2012 transaction table types
                case TableGroup::TransactionHeader:
                case TableGroup::TransactionLine:
                    this.handleGlobalTransTable(sysDictTable);
                    break;
                default:
                    break;
            }
        }
    }
}

Saturday, August 11, 2012

Number Sequence Generation – AX 2012


How to Create/Add a New Number Sequence in AX 2012.


Step1:  Create a new Extended Data Type. As shown in the below screen shot


Step2:  Add the Created EDT in the table.
Create a new table and add the create EDT from the step1 to the table

Step 3: Add the numRef<name> method in which module this belongs to.
For example, let say this belongs to Account Receivable Module, so add it the CustParameters table.
Following is the method needs to be added.

Step 4: Need to add the code in the class “NumberSeqModule<Module Name> “method “loadModule”.
So in our case the class is “NumberSeqModuleCustomer” à load Module ().
Step 5:  Create a new form with the data source in the step 2, as shown in the below.
As shown in the above screen shot the following methods needs to be included in the form.
Below is the code that needs to added ..

Forms\ExampleNumSeq\Methods\numberSeqFormHandler()
NumberSeqFormHandler numberSeqFormHandler()
{
    if (!numberSeqFormHandler)
    {
        numberSeqFormHandler = NumberSeqFormHandler::newForm(CustParameters::numRefNumSeqId().NumberSequenceId,
                                                             element,
                                                             ExampleNumSequence_DS,
                                                             fieldNum(ExampleNumSequence, NumSeqId)
                                                            );
    }
    return numberSeqFormHandler;
}

Forms\ExampleNumSeq\Data Sources\ExampleNumSequence\Methods\create()
public void create(boolean _append = false)
{
    element.numberSeqFormHandler().formMethodDataSourceCreatePre();
   
    super(_append);
   
    element.numberSeqFormHandler().formMethodDataSourceCreate();
}
  
Forms\ExampleNumSeq\Data Sources\ExampleNumSequence\Methods\write()
public void write()
{
    super();
    element.numberSeqFormHandler().formMethodDataSourceWrite();
}

Forms\ExampleNumSeq\Data Sources\ExampleNumSequence\Methods\validateWrite()
public boolean validateWrite()
{
    boolean ret;

    ret = super();
    ret = element.numberSeqFormHandler().formMethodDataSourceValidateWrite(ret) && ret;

    return ret;
}

Forms\ExampleNumSeq\Data Sources\ExampleNumSequence\Methods\delete
public void delete()
{
    element.numberSeqFormHandler().formMethodDataSourceDelete();
    super();
}

Forms\ExampleNumSeq\Data Sources\ExampleNumSequence\Methods\linkActive
public void linkActive()
{
    element.numberSeqFormHandler().formMethodDataSourceLinkActive();
    super();
}
  
Step 6:
Go to Account Receivable à setup àAccounts Receivable parameters, open the form and go to number sequence, over there check Number Sequence Id is listing or not.
In AX 2009, after doing with the above 4 steps it list in the parameters of the accounts receivable.
But in AX 2012 a job needs to run to show in the parameters of the accounts receivable.
Below is the job needs to run…

After running the job, go to Account Receivable à setup àAccounts Receivable parameters form, it show the newly created one as below.


Step7: Once In the parameters form, it is shown need to assign the number sequence code. To assign the number sequence code need to generate the code for it by wizard or it can be created manually.
Go to Organization Administration à Number Sequence àNumber Sequence
A wizard will be opened, click on next button over there, it show the number sequence code for the one which create in the above, below is the screen shot

Click next and Finish button to complete wizard.

Open the forms which created in the step 5 and create the new record in the form it will generate the new number sequence, below is the screen shot.