Wednesday, February 18, 2015

How to find the nth record using the query(qr.addPageRange(postion,postion))

Hi All,

Below is the example of how to find the nth record position using query

static void nthrecordPos(Args _args)
{  
    Query                   q;
    QueryBuildDataSource    qbds;
    QueryRun                qr;
    PurchTable              purchTable;
   
    q = new Query();
    qbds= q.addDataSource(tableNum(PurchTable));
    qbds.addOrderByField(fieldNum(PurchTable, PurchId));
   
    qr = new QueryRun(q);
    qr.literals(true);
    qr.enablePositionPaging(true);
    qr.addPageRange(10,12);
   
    while ( qr.next() )
    {
        purchTable = qr.get(tablenum(PurchTable));
        info(strfmt("%1", purchTable.RecId));
    }
}

Let say in the purchTable having 100 records, wanted to find the 10 to12 th record, by using the "qr.addPageRange(10,12)", it fetches on the 10th, 11th and 12th records.
 

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