Set filter value for ReferenceGroup field

Hello All,
i am just stuck with a requirement in smmActivities Form.

I know how to manually set a filter for a column and then this criteria is also displayed in the grid (so the user can change it).

But how to do this for the ResponsibleWorker field? This is a ReferenceGroup field. I can set a filter (see code below) but the user can’t change it (because it is not displayed in the corresponding grid).

Any hints?

Thanks in advance,
Frank

Code:

smmActivities_ds.query().dataSourceTable(tablenum(smmActivities)).
addRange(fieldnum(smmActivities, ResponsibleWorker)).
value(int642str(smmUtility::getCurrentContactWorker()));

When you use a replacement group, an outer-joined data source is added automatically to get the replacement data. That’s what you have to filter. And because it uses outer join, you can’t use simple range - you have to use a query filter. For example:

q.addQueryFilter(
        q.dataSourceTable(tableNum(HcmWorker)),
        fieldStr(HcmWorker, PersonnelNumber))
    .value(...);

Hi Martin,
thanks for the answer. The filter works (like mine filter), but it is also not displayed in the grid… I tried the following:

qbds = this.query().dataSourceTable(tableNum(smmActivities));
smmActivities_ds.query().addQueryFilter(qbds, 
         fieldStr(smmActivities, ResponsibleWorker)).value('5637147035');

Is there another trick?

Thanks in advance,
Frank

It’s displayed in query definition (Ctrl+F3), so users can change it. But I didn’t realized you asked for seeing it among grid filters. I’ll see if I can find a solution for that…

Actually, I tried my solution and it works - I see the value in grid column filter. Just ensure yourself that you filter by a field that is displayed in the grid. In my example, it means that you have to use a replacement group that contains PersonnelNumber.

If you want to filter by a field that doesn’t exist in the grid, you can’t use “Filter by grid”.

Hello Martin,
thanks again.

You are right - it is displayed there.

But: It is not displayed in the grid (Strg+G). I set the filter to “smmActivities.ResponsibleWorker” (RecId).

Because of the replacement group the value displayed comes from “DirPartyTable(DataSource1).Name”. But the DirPartyTable/DataSource1 is not part of the smmActivities-Form-DataSources …

So the question, how to set the value DirPartyTable(DataSource1).Name, or?

Frank

If you want to filter by RecId, the requirement makes little sense. You can’t expect users to fill Int64 values if they want to filter records. That’s why there are replacement values such as Name.

You don’t see the filter because the field you filter by (ResponsibleWorker) isn’t displayed there. Fields from the replacement group are displayed instead. You have to filter by fields displayed in the grid if you want to see filter in columns’ headers.

The data source is added automatically as runtime, as I already tried to explain in my first reply.

The implementation will be the same as what I already gave you, you just replace table and field names:

Query q = ...
q.addQueryFilter(
        q.dataSourceTable(tableNum(DirPartyTable)),
        fieldStr(DirPartyTable, Name))
    .value(...);

I didn’t test this particular code snippet but I tested the previous one, so it should work.

Hello,

Of course - that was never my intention.

Exactly this is what i am trying to do. BUT: The Form (in the IDE) itself only contains the smmActivities.ResponsibleWorker Field (RecId). I know that the DirPartyTable is automatically added at runtime. The problem ist that “q.dataSourceTable(tableNum(DirPartyTable))” results null.

I try to implement the code in the init method from smmActivities DataSource (after super).

q = this.query();
qbds = q.dataSourceTable(tableNum(DirPartyTable));
if (!qbds)
    warning('Null');
else
    q.addQueryFilter(qbds, fieldStr(DirPartyTable, Name)).value('somevalue');

So that is the point where i am stucked :frowning:


Your code runs when the root data source is being initialized . No other data source exists in the moment. You have to call your code later, e.g. in form’s init() after super().

Nevertheless I also didn’t realize that the data source you need is DirPerson, not DirTable. Now works for me exactly as required.

This is how the query in smmActiovities form look like - it should help you understand what’s going on:

SELECT FIRSTFAST * FROM smmActivities(smmActivities)
USING INDEX ActivityNumberIdx

OUTER JOIN Person, Person FROM HcmWorker(Ref_HcmWorker_ResponsibleWorker)
    ON smmActivities.ResponsibleWorker = HcmWorker.RecId

OUTER JOIN Name, RecId FROM DirPerson(Ref_DirPerson_ResponsibleWorker_DirPerson_FK)
    ON HcmWorker.Person = DirPerson.RecId

OUTER JOIN Person, Person FROM HcmWorker(Ref_HcmWorker_DoneByWorker)
    ON smmActivities.DoneByWorker = HcmWorker.RecId

OUTER JOIN Name, RecId FROM DirPerson(Ref_DirPerson_DoneByWorker_DirPerson_FK)
    ON HcmWorker.Person = DirPerson.RecId

Hello Martin,
just to share the result from my two posts (other - yes i have forgotten to update it - sorry for that).

The problem was, to put the following code in the rigth place. In this case i put the following code in the form’s init() after super().

q = smmActivities_ds.query();
q.addQueryFilter(q.dataSourceTable(tableNum(DirPerson)),fieldStr(DirPerson,Name)).value('SomeValue');

Thanks all for help!
Frank

Yes, that’s what I said in the first paragraph of my previous reply.

Please use “Verify solution” on the replies answering your question.