Skip to main content

Posts

Dynamics AX - Getting the value of a given field regardless of tablebuffer

How to get the value of a given field regardless of which tablebuffer is active. Foreign keys in Dynamics AX are scattered throughout the tables of the system, connecting the modules to each other. For example ItemId fields store the item identification in a lot of tables, for storing information related to the item in question. This example shows how you can write a generic method that gets the value of the field ItemId regardless of which table is active at runtime. The example was originally implemented as a method on a form. The method was able to return the value of the field ItemId regardless of which tablebuffer was active, when the form was called ( element.args().record() ). public ItemId getFormItemId() {     common table; // Generic table buffer     DictTable dt; // Dictionary object for handling table information     // Get the table in question     table = element.args().record();     // Make DictTable object     dt = new DictTable(table.TableId);     return table.(dt.fiel

Debugging and inspecting values of the fields in a form datasource

For debugging purposes code that can inspect the values of the fields in a datasource in a form or a report can be quite handy. This is how it can be done in e.g. the active method of the datasource : QueryBuildDataSource qbds; QueryBuildRange qbr; int dsc,dsi,rc,ri; // Get the number of datasource on the query dsc = queryRun.query().dataSourceCount(); // Loop over datasources for (dsi=1;dsi<=dsc;dsi++) {     qbds = queryRun.query().dataSourceNo(dsi);     info("Table: "+tableid2name(qbds.table()));     rc = qbds.rangeCount();     // Loop over fields     for (ri=1;ri<=rc;ri++)     {         qbr = qbds.range(ri);         info(fieldid2name(qbds.table(),qbr.field())+" value: "+qbr.value());     } }

Overriding SysLastValue Dynamics AX 3.0

This is an old blog entry from my old blog. Today I solved a problem, that has long puzzled me. From Axapta 3.0 (or was it 2.5 can't quite remember) it became best pratice to wrap reports in runbase-report classes. For a long time it has irritated me, that if you called your report class from something else than the menu, you were having trouble overriding syslastvalue, without clearing all saved last value completely. Example: You have a report called from a runbasereport class.For the class you naturally have a output menuitem, that is attached to the menu. So when you call this report, and make selections in the ranges of the query of the report, they are shown in the report dialog, and saved, so that the next time you call your report, the last used selections is being restored for you in the dialog for reuse. However sometime you experience, that the report can be called from BOTH the menu and somewhere else like a form. When you call the report from a form, it is customary to

Subtle but important difference between _ds.executeQuery() and ds.Research()

This is actually an old entry. Been tumbling with a problem for the last few days. A form in our Dynamics AX module for Preventive Maintenance Control was not behaving. The form has "explicit" filter fields that the user can see without having to activate the form filter (CTRL+F3), for setting up filters most commonly used in an easy way. And this is working ok. However at this customer site, the form has been adjusted so that the user can have the form refreshed automatically periodically, and when the users at the customer site were making use of the "explicit" filter combined with the AX's normal filtering (CTRL+F3), the form simply threw away the normal form filtering. I discovered a subtle but very important difference between writing _ds.executeQuery(); (which was the way our code was doing it) and _ds.Research(); The difference is that _ds.Research() will retain the filter ranges in the forms query as they are right now. _ds.executeQuery() will NOT. It

Dynamics AX 4.0 - showing AOS instance

I Dynamics AX version 4.0 the information about on what AOS you are currently running your code, has been removed. In version 3.0 (3-tier) the client showed the AOS instance info. With a development, a test and a production environment at a site, the missing info can be of great annoyance when you are working with clients started in multiple environments. Today I found that other developers and consultants have the same problem, and one developer even solved the problem, with the very usefull hack: http://coolhake.wordpress.com/2008/07/22/configuration-in-title-bar/ Oh yay, saved my day.

Indicating mandatory field in a dialog (RunBase) class.

A classical problem is indicating that a field is mandatory in a dialog, when the field is not bound to a datasource/field in a datasource. Normally fellow developers will tell you that, that is not possible. I found a way to do this. In your Runbase-based class you can implement the putToDialog-method e.g like this: protected void putToDialog() { super(); fieldMask.fieldControl().mandatory(true); } where fieldMask is a DialogField object in your dialog. This will make the field act like it was a mandatory field from a datasource in a form, showing a red-wavy line under the field, and requiring the field to have a value. Attention: Your class has to run on the client.If you set your class to run on the server, you get a run-time error, when the fieldMask.FieldControl()-call is made.

Getting the active company accounts programmatically

While working on a client case where custom made data export was needed, I coded some classes to make the export. While working with the code, I decided it would be a good idea to make the currently chosen company id a part of the file name when exporting, as the customer have several company accounts, and we need to export from all of them. I spent a little time to find out how to get the current selected company account id and I came up with: static void Job77(Args _args) { ; info(appl.company().ext()); } So I made a function for constructing the file name and put the appl.company().ext() bit in that.