问题
Table table;
select *
from table
where this.id != table.id
&& this.foo(table);
I am trying to make a selection from a table in X++ code.
The table is compared against a record from the table (this
).
A record shall be added to the selection if the id of the record and another record from the table do not equal and several other conditions in foo()
evaluate to true.
The plan is to make this.foo(table)
evaluate the record together with each other record in the table.
When I insert the code from foo()
directly into the call, it works just fine. However, when calling the method, it appears like table
does not hold any reference.
What am I not understanding about the way, select statements work? Are methods just evaluated once?
回答1:
You cannot use methods in the where
expression (nor in any other part, for that matter) of the select
statement in AX. Your example will not compile successfully.
You can either try incorporating the logic of your foo
method in the where
expression or iterate through the result of the select
statement and call method foo
for each record individually e.g.:
Table table;
while select table
where table.id != this.id
{
if (this.foo(table))
{
info(table.id);
}
}
来源:https://stackoverflow.com/questions/51901767/use-methods-in-where-statements