# Filter records in a Form based on tempDB records

**URL:** <https://www.dynamicsuser.net/t/filter-records-in-a-form-based-on-tempdb-records/58578>\
**Category:** Developer Forum\
**Created:** [September 14, 2015, 9:52am UTC](https://www.dynamicsuser.net/t/filter-records-in-a-form-based-on-tempdb-records/58578 "2015-09-14T09:52:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pixie7](https://avatars.discourse-cdn.com/v4/letter/p/74df32/32.png) [@pixie7](https://www.dynamicsuser.net/u/pixie7)\
**Post date:** [September 14, 2015, 9:52am UTC](https://www.dynamicsuser.net/t/filter-records-in-a-form-based-on-tempdb-records/58578/1 "2015-09-14T09:52:52Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![MartinDrab](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@MartinDrab](https://www.dynamicsuser.net/u/MartinDrab)\
**Post date:** [September 14, 2015, 10:24am UTC](https://www.dynamicsuser.net/t/filter-records-in-a-form-based-on-tempdb-records/58578/2 "2015-09-14T10:24:57Z")

</div>

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_).

---

<div class="post-metadata">

**Author:** ![pixie7](https://avatars.discourse-cdn.com/v4/letter/p/74df32/32.png) [@pixie7](https://www.dynamicsuser.net/u/pixie7)\
**Post date:** [September 14, 2015, 11:09am UTC](https://www.dynamicsuser.net/t/filter-records-in-a-form-based-on-tempdb-records/58578/3 "2015-09-14T11:09:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![MartinDrab](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@MartinDrab](https://www.dynamicsuser.net/u/MartinDrab)\
**Post date:** [September 14, 2015, 11:45am UTC](https://www.dynamicsuser.net/t/filter-records-in-a-form-based-on-tempdb-records/58578/4 "2015-09-14T11:45:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pixie7](https://avatars.discourse-cdn.com/v4/letter/p/74df32/32.png) [@pixie7](https://www.dynamicsuser.net/u/pixie7)\
**Post date:** [September 14, 2015, 11:49am UTC](https://www.dynamicsuser.net/t/filter-records-in-a-form-based-on-tempdb-records/58578/5 "2015-09-14T11:49:09Z")

</div>

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