Discussion:
Adding datasource in form runtime (sales order)
(too old to reply)
Henrik Berg Andersen
2010-01-20 18:13:02 UTC
Permalink
Hi folks.

I am trying to do this:


form = new Form(formstr(PurchTable));

inventDim_fbds = form.datasource(3);
new_fbds = form.addDataSource(tablestr(InventLocation));
new_fbds.table(tablenum(InventLocation));
new_fbds.joinsource(inventDim_fbds.id());

args = new Args(form);
args.object(form);
formRun = classFactory.formRunClass(args);
formRun.init();
formRun.run();
formRun.detach();

If I try run time in a job to add a datasource to a simple form like for
instance the form InventDim then the above code will work just fine (I did
not include variable declarations in the text). However, as soon as I try and
do it on a form, in which controls are autodeclared then it crashes with a
stack trace saying that the control does not have this or that method or is
not initialized.

For the above example it will say that a grid control named LineSpec does
not have the method visibleRowsValue. But grid controls have that method.

I did not change anything in the form in the AOT. I only add the data source
run time. I tried various stuff to figure out why it does not want to run. If
I change the form in the AOT by adding InventLocation to the datasource then
it will run just fine and not complain about that LineSpec control. If the
form is standard with no modifications and I add the datasource runtime it
don't want to work.

Why not?
--
Kind regards,
Henrik Berg Andersen
amir nazim
2010-01-24 02:06:01 UTC
Permalink
You should override the init method of the datasource "InventDim" and after
super call write similar sort of code like.

qbds_id = this.query().datasourcetable(tablenum(inventdim));
qbds_iL = qbds_id.addDataSource(tableNum(inventlocation));
qbds_iL.joinMode(....);
qbds_iL.relation(true);

Thank
Amir
http://msdax.wordpress.com/
Post by Henrik Berg Andersen
Hi folks.
form = new Form(formstr(PurchTable));
inventDim_fbds = form.datasource(3);
new_fbds = form.addDataSource(tablestr(InventLocation));
new_fbds.table(tablenum(InventLocation));
new_fbds.joinsource(inventDim_fbds.id());
args = new Args(form);
args.object(form);
formRun = classFactory.formRunClass(args);
formRun.init();
formRun.run();
formRun.detach();
If I try run time in a job to add a datasource to a simple form like for
instance the form InventDim then the above code will work just fine (I did
not include variable declarations in the text). However, as soon as I try and
do it on a form, in which controls are autodeclared then it crashes with a
stack trace saying that the control does not have this or that method or is
not initialized.
For the above example it will say that a grid control named LineSpec does
not have the method visibleRowsValue. But grid controls have that method.
I did not change anything in the form in the AOT. I only add the data source
run time. I tried various stuff to figure out why it does not want to run. If
I change the form in the AOT by adding InventLocation to the datasource then
it will run just fine and not complain about that LineSpec control. If the
form is standard with no modifications and I add the datasource runtime it
don't want to work.
Why not?
--
Kind regards,
Henrik Berg Andersen
Henrik Berg Andersen
2010-01-25 09:16:01 UTC
Permalink
Hi Amir.

Changing the query in the datasource is not my aim. I am trying to add a
form datasource, which is a different type of data source than a query data
source.

The reason for this is that fields on the form datasource can be added as
controls on the form.

Kind regards,
Henrik Berg Andersen
--
Kind regards,
Henrik Berg Andersen
Post by amir nazim
You should override the init method of the datasource "InventDim" and after
super call write similar sort of code like.
qbds_id = this.query().datasourcetable(tablenum(inventdim));
qbds_iL = qbds_id.addDataSource(tableNum(inventlocation));
qbds_iL.joinMode(....);
qbds_iL.relation(true);
Thank
Amir
http://msdax.wordpress.com/
Post by Henrik Berg Andersen
Hi folks.
form = new Form(formstr(PurchTable));
inventDim_fbds = form.datasource(3);
new_fbds = form.addDataSource(tablestr(InventLocation));
new_fbds.table(tablenum(InventLocation));
new_fbds.joinsource(inventDim_fbds.id());
args = new Args(form);
args.object(form);
formRun = classFactory.formRunClass(args);
formRun.init();
formRun.run();
formRun.detach();
If I try run time in a job to add a datasource to a simple form like for
instance the form InventDim then the above code will work just fine (I did
not include variable declarations in the text). However, as soon as I try and
do it on a form, in which controls are autodeclared then it crashes with a
stack trace saying that the control does not have this or that method or is
not initialized.
For the above example it will say that a grid control named LineSpec does
not have the method visibleRowsValue. But grid controls have that method.
I did not change anything in the form in the AOT. I only add the data source
run time. I tried various stuff to figure out why it does not want to run. If
I change the form in the AOT by adding InventLocation to the datasource then
it will run just fine and not complain about that LineSpec control. If the
form is standard with no modifications and I add the datasource runtime it
don't want to work.
Why not?
--
Kind regards,
Henrik Berg Andersen
g***@gmail.com
2012-03-24 22:50:15 UTC
Permalink
Hi Henrik,

I’m trying to do exactly the same thing as you, dynamically add a data source on a form and display the fields, but I cannot get it to work (AX 4.0).
I was wandering if you managed to make it work. If so, could you please share the procedure?

Thank you!

Sasho

Loading...