Sunday, March 22, 2015

Outbound file generation using File system adapater in AX 2012

Hi All,

Here is example to generate the outbound Xml file using X++ code. This is not the new thing but just posting the info

1. Generating the outbound xml file for selected record or single record - using document service(file system adapter).
2. Generating the outbound xml file for all records( i.e. specified criteria on the query) - using document service(file system adapter).

Example: Generating the outbound xml file for selected record or single record.
Below is the code to generate the outbound xml file for the selected record.
static void GenerateXmlSelectedRecord(Args _args)
{
    AxdSendContext      axdSendContext  = AxdSendContext::construct();
    AifEntityKey        aifEntityKey    = AifEntityKey::construct();
    AifEntityKeyList    aifEntityKeyList = AifEntityKeyList::construct();
    Map                 keyData;
    AifConstraintList   aifConstraintList   = new AifConstraintList();
    AifConstraint       aifConstraint       = new AifConstraint();
    CustTable           custTable;
    int i,j;
    CustCustomerService CustCustomerService = CustCustomerService::construct();
    ;
    custTable = CustTable::find('Cust001');

    keyData = SysDictTable::getKeyData(custTable);
    aifEntityKey.parmTableId(custTable.TableId);
    aifEntityKey.parmRecId(custTable.RecId);
    aifEntityKey.parmKeyDataMap(keyData);

    aifEntityKeyList.addEntityKey(aifEntityKey);


    axdSendContext.parmXMLDocPurpose(XMLDocPurpose::Original);
    axdSendContext.parmSecurity(false);


    aifConstraint.parmType(AifConstraintType::NoConstraint) ;
    aifConstraintList.addConstraint(aifConstraint) ;

    info(strFmt("%1",custTable.AccountNum));
    AifSendService::SubmitDefault(  classnum(CustCustomerService),
                                aifEntityKey,
                                aifConstraintList,
                                AifSendMode::Async,
                                axdSendContext.pack());
}

Example: Generating the outbound xml file for all records( i.e. specified criteria on the query).
Below is the code to generate the outbound xml for all the records or specified criteria.

static void GenerateMutiplerecords(Args _args)
{
    CustTable           custTable;
    AxdSendContext      axdSendContext      = AxdSendContext::construct();
    AifEntityKey        aifEntityKey        = AifEntityKey::construct();
    AifConstraintList   aifConstraintList   = new AifConstraintList();
    AifConstraint       aifConstraint       = new AifConstraint();
    AifEndpointList     endpointList;
    AifActionId         actionId;
    Query               query;
    QueryBuildDataSource    qbds;

    query               = new Query(queryStr(AxdCustomer));
    AxdSend::removeChildDs(query);

    actionId            = AifSendService::getDefaultSendAction(classnum(CustCustomerService), AifSendActionType::SendByQuery);
    aifConstraint.parmType(AifConstraintType::NoConstraint);
    aifConstraintList.addConstraint(aifConstraint) ;
    endpointList        = AifSendService::getEligibleEndpoints(actionId, aifConstraintList);

    AifSendService::SubmitFromQuery(actionId,endpointList,query,AifSendMode::Async);
}

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.