Filter records in a Form based on tempDB records

Form/Prodtable, I need to filter some records based on complex criteria not manageable by query range

In the init method of the form I’ve just added the following instr which create the ProdTableTmp (tempDB having just one field ProdId and a relation to ProdTable)

if (element.args().dataset() == tableNum(BOMVersion))

{

BOMVersion = element.args().record();

this.createProdTableTmp(bomVersion);

}

debugging I can see the tmp records created successfully

and in the init() of the ProdTable Datasource the following;

super();

if (element.args().dataset() == tableNum(BOMVersion))

{

qbds = this.query().dataSourceTable(tablenum(ProdTable)).addDataSource(tableNum(ProdTableTmp));

qbds.relations(true);

qbds.joinMode(JoinMode::ExistsJoin);

}

The ProdTableTmp is not defined as Datasource in the form

The form doesn’t show any record, same result adding the tempdb as datasource joined to prodtable (done only for test purpose)

Does a tempdb table be linked to a regular table in a form? If not , any solution will be appreciated…

You asked the query to create a ProdTableTmp buffer, but you didn’t provide any data, therefore the query doesn’t return anything. That’s expected.

Set the temporary buffer to the QueryRun object through setRecord().

Alternatively, add ProdTableTmp as a datasource and either link it with the data through linkPhysicalTableInstance(), or disable the datasource (if the record argument isn’t BOMVersion).

Tks Martin, In which method of the form I can add the queryrun().setrecord()? I 'didn’t found examples in the AOT…

Well, I tried it and although the setRecord() works well with normal queries, there is some problem with forms. Rather than wasting too much time with investigating, I suggest you use the other approach I described.

Alternatively, you could wait until AX initalized the QueryRun object (e.g. in run() below super()), get a reference to the table buffer (e.g. SomeTable_ds.queryRun(get(tableNum(…)) and insert data there (with insert() as usual). But the other approach (using a form datasource and disabling the QueryBuildDataSource if it isn’t needed) makes better sense to me.

I managed by myself using ProdReferences classes and adding a new method here, easy and quick!