Question

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.

Was it helpful?

Solution

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());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top