Use methods in where statements

半腔热情 提交于 2019-12-20 02:56:25

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!