Query range not equal to zero

2019-07-02 12:26发布

I'm in AX 2012 R2 environment.

I would like to add a query range to HcmEmployment table and filter out rows that have a LegalEntity value = 0.

The following code fails at runtime with the exception "Invalid Range".

qbrLegalEntity = qbds.addRange(fieldNum(HcmEmployment, LegalEntity));
strRangeCondition = '(%1 != %2)';
qbrLegalEntity.value(strFmt(strRangeCondition, 
                        fieldStr(HcmEmployment, LegalEntity),
                        queryValue("0")));

Is it possible to code this range condition?

Thank you.

1条回答
Evening l夕情丶
2楼-- · 2019-07-02 12:49

Do not make it harder:

qbds.addRange(fieldNum(HcmEmployment,LegalEntity)).value(SysQuery::valueNot(0));

The reason for your failed query expression was the use of queryValue("0") which quotes the zero. Changing that to 0 would work as well, but again too laborious.

And even shorter is:

qbds.addRange(fieldNum(HcmEmployment,LegalEntity)).value('!0');

To diagnose query errors take a look on the SQL generated:

info(qbds.toString());
查看更多
登录 后发表回答