Question Status

Suggested Answer
Eitan Mizrahi asked a question on 4 Apr 2012 1:51 PM

In Dynamics AX 2009 -

How can I change the datasource of a grid on runtime?

I did :

MyGrid.datasource("myDataSourcename");

MyGrid.executeQuery();

// even I did : myDataSource_ds.refresh(); myDataSource_ds.refreshEx(-1); myDataSource.reseach(); but in vain.

What is wrong in my code, and how can I resolve the problem?

 

Thanks :)

 

Reply
Suggested Answer
gl00mie responded on 6 Apr 2012 11:41 AM

That's kind of odd to change a DS at run time. What exactly do you want to achieve? Why don't you place two grids on a form - each with it's own DS - and make visible one of them at a time?

Reply
Eitan Mizrahi responded on 7 Apr 2012 11:17 PM

I don't want to place two grid - just need to change its datasource.

I need a generic solution for above (some fundamental I write for general use).

Thanks :)

Reply
Suggested Answer
gl00mie responded on 7 Apr 2012 11:52 PM

Em... AX is not quite a development platform intended to create fancy forms. It's a business application and it has some features that are incompatible with "polymorphic" forms, such as user form setup, access rights setup which requires a form to have all the necessary datasources at a design time, workflows, document management, etc. Besides the AX kernel performs an access rights check for all the tables bound to form data sources only at a form's initialization, so if you try to change a datasource's table after that you'll also have to check the access rights by yourself.

Anyway if you're looking for a generic solution look at the SysTableBrowser form.

Reply
Eitan Mizrahi responded on 8 Apr 2012 3:03 AM

I have two datasources on the form (not two grid - the grid is too complicated ...)

At first time the grid is linked to datasource1, and on runtime I need to link it to datasource2.

I don't need to build any new columns on runtime.

I think this has less problems as you have described, since I only need to link to a datasource, that is already on the form.

 

(My code is like : myGrid.dataSource("datasource2_name");

 but this doesn't change the datasource).

 

Thanks :)

Reply
gl00mie responded on 8 Apr 2012 10:57 AM

What do you mean when you say "to link a grid to a datasource"?

Reply
Eitan Mizrahi responded on 8 Apr 2012 11:52 AM

The grid has datasource property.

Whe I do myGrid.dataSource(datasource_name) I suppose the grid should be linked to the datasource, but this doesn't work (the grid on the screen doesn't change at all).

Thanks :)

Reply
gl00mie responded on 8 Apr 2012 12:15 PM

And what do you think should change if you somehow link a grid with another datasource? Note also that datasources can be linked (for instance inner join'd) and a grid can display fields from several linked datasources while being linked with only one of them via it's "datasource" property. Once again what exactly do you want to achieve by changing the datasource your grid is linked with?

Reply
Eitan Mizrahi responded on 10 Apr 2012 3:57 AM

Suppose there is a temporary table and you need to link some tables to the temporary table (kind of an on/off filter).

The temporary table need to be the first in query (you cannot do this otherwise), and the grid should be linked to the temporary table. For that I build a new query based on the original query (not obvious thing at all), but therefore I need to delcare the temporary table datasource as the datasource of the grid, and that's complete my issue. MyGrid.datasource(...) doesn't work,

(It is for speeding up - the temporary table acts as a filter table, which is the small table is on the top of the query ... A filter table may have records, which I can insert into it fastly by insert_recordset ...).

, but I think I found a better solution which is having one single datasource (no changes on the grid), and changing the datasource table property. Once it points to the temporary, and once to the general table (also need to make some little fixes on the query behind). Tommorow I'll check that out, and find whether it solves the issue mentioned.

 

Thanks :)

Reply
Suggested Answer
gl00mie responded on 6 Apr 2012 11:41 AM

That's kind of odd to change a DS at run time. What exactly do you want to achieve? Why don't you place two grids on a form - each with it's own DS - and make visible one of them at a time?

Reply
Suggested Answer
gl00mie responded on 7 Apr 2012 11:52 PM

Em... AX is not quite a development platform intended to create fancy forms. It's a business application and it has some features that are incompatible with "polymorphic" forms, such as user form setup, access rights setup which requires a form to have all the necessary datasources at a design time, workflows, document management, etc. Besides the AX kernel performs an access rights check for all the tables bound to form data sources only at a form's initialization, so if you try to change a datasource's table after that you'll also have to check the access rights by yourself.

Anyway if you're looking for a generic solution look at the SysTableBrowser form.

Reply