Showing posts with label form. Show all posts
Showing posts with label form. Show all posts

Wednesday, March 31, 2010

How to set the language used on forms and menus

Ax is available in many languages (approx 45 I believe). It comes in Spanish, English, Polish, German, Arabic, ... thereby underlining it's global presence.

In reports, you can use any supported language, weather you bought a license key for it or not.

This policy makes senses, as your company, your customers or vendors may not speak the same language. When you exchange documents (for example an order), you need to understand its contents.

I had a post about how to change the language in a report a while back.

Another thing is the user interface, the client you do your every day work in. You can set the language used in forms and menus with the user options. You can find them under Administration - Users - User Options.

In this setting, you are limited to the languages you bought a license for.

Now you can set the language used in the user interface by code as well. And strangely enough, this way you are not limited to the set of licensed languages (this applies to MS Dynamics Ax 2009 SP1).

You can set the language like this

infolog.language('en-us');

Play around with it and see what's available!



Tuesday, March 30, 2010

How to filter records in a form by code

The standard filter functionality in Ax forms is a neat and powerful feature.
Using this filter functionality in your code is something you'll definitely use at some point in time as a programmer.

Although it's possible to do it in a single line of code, I prefer a 3 step solution. That way it's more flexible.
Let me show you by example. We'll filter the customers records in form CustTable, only showing customers with currency USD.

Step 1: Declare a class variable
In the ClassDeclaration method of the form, define a range.

QueryBuildRange CurrencyQBR;

Step 2: Instantiate the new range.
In the init method on the datasource of the form, you assign the range to a specific field (after the super call).

public void init()
{
super();

CurrencyQBR = this.query().dataSourceName('CustTable').addRange(fieldnum(CustTable,Currency));
}

Step 3: In the last step, you assign a value to the range.
This is done in the executeQuery method on the same datasource of the form. Before the super call. Like this:

public void executeQuery()
{ ;

CurrencyQBR.value(queryvalue('USD'));

super();
}

You're done! When you open the form, your customer records are filtered, you only get the customers with currencycode USD set up.




Like I said in the intro of this post, this can be done in one line of code as well.
In the init method of the form datasource, after the super call, place this code:

this.query().dataSourceName('CustTable').addRange(fieldnum(CustTable,Currency)).value(queryvalue('USD'));

But this way, it's fixed. If you choose the 3 step method, you could for example use a variable in the range value. The way to go would be to place an input field on your form, get the value from it and supply it in the executeQuery method.

For example like this:

public void executeQuery()
{ ;

CurrencyQBR.value(queryvalue(MyInputField.text()));

super();
}

Just make sure the executeQuery method is executed, thus applying the desired filter (maybe be using a button on your form to activate it).
Of course it's possible to combine multiple querybuildranges.

Friday, May 22, 2009

Forms forms forms

Microsoft constantly works on the look and feel of its software. So does Axapta change appearances. Sometimes for the better, sometimes ... not so.
What I personally do not like in Ax 2009: All those different forms, creeping out of the current workspace. Your Windows menu bar really gets crowded like that.

If you are like me and want your Axapta forms to stay in the Axapta workspace, there is a little thing you can do.

Change the Class SysSetupFormRun , add this little line of code before the super call of the init method:

if(this.form().design().windowType()==FormWindowType::Standard)
this.form().design().windowType(FormWindowType::Workspace);


Now that's better, isn'it?


Greetz,

Willy

Sunday, April 26, 2009

Number of records in a form

Have you ever needed the number of rows that are returned by the executeQuery method on the datasource of a form? For example to show some progress display while you evaluate each record individually?



Not available in earlier versions of Dynamics Ax aka Axapta, but now it is:



yourdatasource_ds.numberOfRowsLoaded();



Easier then doing a select count statement, not?

(The MSDN help information (Ax 2009 SDK) is rather limited for this function.)


Greetings,



Willy.