Tuesday, April 9, 2013

Data filteration in dialog box In Microsoft Dynamics AX 2012:

Let say for example, dialog box contains 2 dialog fields i.e. Customer group and Customer account.
Every customer is tagged to one customer group, so now when you enter the customer group in the dialog field of the customer group, the related customer accounts which are tagged to that customer group needs to be shown in the customer account dialog field.

Now to go the setup of the dialog box as shown in the screen shot

Override the control of the customer account dialog field with below code with the control name of the customer account dialog as “Fld2_1” as shown in the above screens hot.
public void Fld2_1_Lookup()
{
    SysTableLookup          sysTableLookup;
    QueryBuildDataSource    queryBuildDataSource;
    QueryBuildRange         queryBuildRange;
    Query                   query;
    FormStringControl       _control;
    ;

    sysTableLookup = SysTableLookup::newParameters(tablenum(CustTable),dialogCustAccount.control());

    sysTableLookup.addLookupfield(fieldnum(CustTable, AccountNum));
    sysTableLookup.addLookupfield(fieldnum(CustTable, CustGroup));

    query = new Query();

    queryBuildDataSource = query.addDataSource(tablenum(CustTable));
    queryBuildRange = queryBuildDataSource.addRange(fieldnum(CustTable, custGroup));
    queryBuildRange.value(dialogCustGroupId.value());

    sysTableLookup.parmQuery(query);

    sysTableLookup.performFormLookup();
}

Now override the “dialogPostRun()” method from the override methods and the code after super() call as shown below.
public void dialogPostRun(DialogRunbase dialog)
{
    super(dialog);
    dialog.formRun().controlMethodOverload(true);
    dialog.formRun().controlMethodOverloadObject(this);
}

Result:


Below is the link for the entire code:
https://skydrive.live.com/?cid=0b5669924378bbb7#cid=0B5669924378BBB7&id=B5669924378BBB7%21232

Thursday, November 15, 2012

How to have different permission for the user in the different companies in AX 2009.


How to have different permission for the user in the different companies in AX 2009.

For example if we are having 2 companies i.e. ‘CEU’ and ‘CEC’ in AX 2009.So if the user-x will be having the same permissions in both companies.
Now we want to have the user to have the different permission in both the companies ‘CEU’ and ‘CEC’.
i.e. let say the user-x in the company ‘CEU’ to have permission under the module ‘Accounts Payable’ for sections ‘Journals’ and ‘Inquiries’.
For the other company ‘CEC’ to have the permission under the module ‘Accounts Payable’ for the section ‘Reports’ only.

So to achieve this we need to have the following setup to be done. Below is the step by step procedure to be followed.
Step 1: Create a new Domain id in the Axapta 2009.
In Module Administration – setup – Domains. 

Step 2: Go to ‘Company accounts’ tab in the same form, over there add the company account ‘CEC’ under the created new Domain ‘Test’ as shown in the below figure
Step 3: Now go to the user group
In Module Administration – setup – User group, open the form.
Over here select the user group for which we wanted to have different permission in 2 companies.
In this let take the user group ‘PR complete’.
Step 4: Now click on the button ‘Permission, it takes you to ‘User group Permission’ form.
Over here we can see the domain id against the User group.

Step 5:  Now select the ‘Admin’ Domain id and go to permission tab. Under the permission tab give the permission 
Step 6: Now again come back the tab ‘Overview’, select the ‘Test’ domain id and switch to the ‘permission’ tab again.
Under the Accounts Payable – give full control for ‘Reports ‘as shown in the screen shot.
Now, login with any of the user which is in the user group ‘PR complete’.
So when the user login
In the Company ‘CEU’ will be able to see the under Account Payable – ‘Journals’ and Inquiries’ and in the company ‘CEC’, Accounts Payable – ‘Reports’, ‘Journals’ and Inquiries’.

Since we didn’t any give any permission for Account Payable – ‘Journals’ and Inquiries’ under the domain ‘Test’ for ‘Journals’ and ‘Inquiries’ but still able to see in the company ‘CEC’. The reason is that in the other domain id ‘Admin’ it also contains the company account ‘CEC’ in it, so it showing up those in it.

So this is how we can different permission in the different companies by using ‘Domain id’ in the user group.




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.