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!
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)
try using
dsInventTable.query(qMyQuery);
instead of
dsInventTable.queryRun(new QueryRun(qMyQuery);
Kind regards
--
Mathias Füßler
my blog: http://starside.eu
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.
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.
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.
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!
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.
dBDS.linkType(FormLinkType::InnerJoin);