Hey folks,
I'm attempting to do the following query using the Query objects:
SELECT * FROM inventTable EXISTS JOIN * FROM inventItemGroup
WHERE inventTable.ItemGroupId == inventItemGroup.ItemGroupId
&& ((inventItemGroup.myFlag == NoYes::Yes))
This X++ query runs and returns inventTable records that have
inventItemGroup rows with a custom myFlag set to Yes.
i.e. ItemGroup Stuff has myFlag set to yes, ItemGroup Junk has myFlag set
to no. Item A is a part of item group Stuff and Item B is a part of item
group Junk. When the InventTable form opens, I'd like only Item A to be
returned.
However, when I try using the Query objects, it doesn’t do the expected
operation:
form InventTable.init()
Query q = new Query();
QueryBuildDataSource qB,qBItemGroup;
QueryBuildRange qBr;
;
super();
qB = q.addDataSource(tableNum(InventTable));
qBItemGroup =qB.addDataSource(tableNum(InventItemGroup));
qBItemGroup.addLink(fieldNum(InventTable,ItemGroupId),fieldNum(InventItemGroup,ItemGroupId));
qBItemGroup.joinMode(JoinMode::ExistsJoin);
qBr = qBItemGroup.addRange(fieldNum(InventItemGroup,myFlag));
qBr.value(enum2str(NoYes::Yes));
this.query(q);
What happens is that rows are returned from inventTable, but they are
tripled up and the range criteria for myFlag is being ignored.
i.e.
A
A
A
B
B
B
instead of just
A
Any ideas how implement such a query?
Thanks!
|