Jul 11, 2012

Example of AdObject class in Dynamics AX 2009

If you want to know the user details in a domain in Axapta. Here is a class called AdObject, by using this class we can get the Active directory information.

I am sharing a simple job which will describe how to know the user name and mail address of a particular valid domain user.

Just try it this job if you want to know how this class works.


Static void AdObjectExample(Args _args)
{
    AdObject adObject = new AdObject("venkateswararao.g");
    str Name;
    str MailAddr;
    #define.givenname ("Name")
    #define.mail ("Mail-Id")

    ;
    if(!adObject)
    {
        checkFailed("given Name is Invalid");
    }
    else if(adObject.found())
      {
        Name = adObject.getValue("#givenname");
        MailAddr  = adObject.getValue("mail");
        info("Name is "+Name);
        info("Mail Address is "+MailAddr);

      }
}


You will get a screen as shown below

Differences among reread(), refresh(),research() datasource methods in dynamics ax 2009.

Commonly after opened the form we need to do some operations with existing data. In few cases we need to interact with data base again and again in order to do. For that we will use these methods. But so many developers are confusing to use these methods.

refresh() : this method will refresh the data in the data source cache. But it will not interact with the data base to fetch the new/updated record values. Whatever values have fetched in the previous query will store in data source cache, this method will just refresh the data source cache only.

reread(): this method will interact with the data base and runs the query against the data base in order to fetch the new/updated record values. But this will not show the updated values in the form until calling the refresh method. That means it will update the data source form cache only but not existing form control values.
So it is better to call the methods as shown here, like reread and after refresh methods in order to fetch the new / updated values from the data base.

formDataSource.reread()
formDataSource.refresh()


research():Calling research() will rerun the existing form query against the database, therefore updating the list with new/removed records as well as updating all existing rows.

Jul 10, 2012

finding all data sources in a form through code


static void AllDataSourcesInForm(Args _args)
{
    Args args = new Args();
    FormRun fr;
    FormBuildDataSource formBuildDataSource;
    counter i;
    ;
 
    args.name("CustTable");
    fr = ClassFactory.formRunClass(args);
    for(i=1 ; i<=fr.form().dataSourceCount();i++)
    {
        formBuildDataSource = fr.form().dataSource(i);
        info(new DictTable(formBuildDataSource.table()).name());
    }
}