Query range not equal to zero

RT. picture RT. · May 13, 2014 · Viewed 15.5k times · Source

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.

Answer

Jan B. Kjeldsen picture Jan B. Kjeldsen · May 14, 2014

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());