Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Change a form's datasource query from code

1,340 views
Skip to first unread message

Strider

unread,
Jun 18, 2008, 1:11:01 PM6/18/08
to
Hello.

I need to show the InventTable (Items) form from code, and filter it's
contents using a Query object I have also constructed from code. I have tried
the following, but it does not seem to work:

FormRun frmInventTable;
FormDataSource dsInventTable;
Query qMyQuery;
;

qMyQuery = new Query();
// Initialize query object starting from InventTable here
//

frmInventTable = ClassFactory::formRunClassOnClient(new
Args(formStr(InventTable)));
frmInventTable.init();
dsInventTable= frmInventTable.dataSource(1);
dsInventTable.queryRun(new QueryRun(qMyQuery);

frmItems.run();
frmItems.wait();


The items form is displayed but my query is ignored and no filter is applied!
Please note that the Query must be constructed from code outside the
InventTable form.

Has anyone done this allready?
Any help would be greatly appreciated.
Thanks!

Axel Kühn

unread,
Jun 18, 2008, 2:12:01 PM6/18/08
to
Hi Strider,

please take a look at my blog. There you can find an article describing this..
http://blog.ak-home.net/PermaLink,guid,35a003b9-c75e-4dd8-a32e-65c5949815f5.aspx

You can also download an example XPO.
--
Sincerely yours
Axel Kühn (visit my Dynamics AX blog at: http://blog.ak-home.net)

Mathias

unread,
Jun 18, 2008, 2:13:00 PM6/18/08
to
Hello Strider,

try using
dsInventTable.query(qMyQuery);
instead of
dsInventTable.queryRun(new QueryRun(qMyQuery);

Kind regards
--
Mathias Füßler
my blog: http://starside.eu

Strider

unread,
Jun 19, 2008, 4:45:00 AM6/19/08
to
Thanks Alex,

Unfortunately, I need to replace the entire query object reference of the
datasource with my own query object. It doesn't seem possible to be able to
do that, either by using the FormDataSource.query or the
FormDataSource.queryRun
properties.

Strider

unread,
Jun 19, 2008, 5:09:01 AM6/19/08
to
Thanks for replying Mathias.

I've tried replacing the FormDataSource.query with my query but I end up
getting a form with no data. The problem is that the InventTable form has
many linked data sources under the main datasource, which are removed when I
set the query property.

Mathias

unread,
Jun 19, 2008, 5:24:01 AM6/19/08
to
Hello Strider,

here is an example that uses a new query based on the inventtable query. It
adds one range only.

FormRun frmInventTable;
FormDataSource dsInventTable;
Query qMyQuery;
;

frmInventTable = ClassFactory::formRunClassOnClient(new
Args(formStr(InventTable)));
frmInventTable.init();

dsInventTable= frmInventTable.dataSource(1);
//get invent table query
qMyQuery = new Query(dsInventTable.query());


// Initialize query object starting from InventTable here

qMyQuery.dataSourceTable(tablenum(InventTable)).addRange(fieldnuM(InventTable, ItemID)).value("test");
dsInventTable.query(qMyQuery);

frmInventTable.run();
frmInventTable.wait();

I hope this will help.

Strider

unread,
Jun 20, 2008, 5:04:00 AM6/20/08
to
Thanks.

I used a similar approach, modifying the existing datasource query and it
worked (at least when adding ranges to the existing datasources).
There is still a problem though. If I add a new QueryBuildDatasource to the
query (e.g. InventModelGroup),
no corresponding FormBuildDataSource is added to the form. When the form
opens, the additional table is not joined in the statement issued to the
database server.

I tried creating the FormBuildDataSource manually but it still doesn't work!

Mathias

unread,
Jun 20, 2008, 7:03:01 AM6/20/08
to
Hello,

add a new formdatasource on runtime is not easy and works not very well.

Here is an example to add a new formdatasource. If you use it on form
Inventtable you will most likly get an error because of some code that is in
the init method of the form (for testing you have to remove this codeline).
There is this strange behavior of the formcontrols that are modified by x++
are not formcontrols anymore, but formdatasources? Anyway here is the example
(does not work very well but you can see - good luck :)

FormRun frmInventTable, newFrmInventTable;
FormDataSource dsInventTable;
Query qMyQuery;
FormBuildDataSource dBDS;
FormStringControl fsc;
args args = new Args();
;

frmInventTable = ClassFactory::formRunClassOnClient(new
Args(formStr(InventTable)));
frmInventTable.init();

dsInventTable= frmInventTable.dataSource(1);

//add new FormDataSource
dBDS = frmInventTable.form().addDataSource("InventModule");
//set Table
dBDS.table(tablenum(InventModelGroup));
//set Join
dBDS.joinSource(dsINventTable.name());
dBDS.linkType(Joinmode::InnerJoin);

// add control to design
fsc =
frmInventTable.form().design().control("Grid").addDataField(dBDS.id(),
fieldnum(InventModelGroup, Name));
//create new formrun based on current form
args.object(frmInventTable.form());
//close current formrun
frmInventTable.close();

newFrmInventTable = new Formrun(args);
newFrmInventTable.init();
newFrmInventTable.run();
newFrmInventTable.wait();


For further information take a look at class systablebrowser.

Jack

unread,
Jun 20, 2008, 11:49:03 AM6/20/08
to
linkType is not JoinMode type, it is FormLinkType enum, correct way would be:

dBDS.linkType(FormLinkType::InnerJoin);

0 new messages