Talk:Expressions in query ranges
From Axaptapedia
Please if the previous editor of the article reads this, add a note somewhere on this page. The examples shown in the new version of the article are not related to the special Expressions syntax!
I've pasted the previous edit below, pending resolution of this issue
The syntax that is shown in this edit unfortunately does not work for the Query Expressions syntax, or at least I don't think so!
If you can find a way to do something similar to:
queryBuildRange.value(strFmt('((Dimension[1] == %1) || (Dimension[2] == "%2"))', "some dim1 value", "some dim2 value"));
then please add it here, and modify the article accordingly AJ
Previous edit below - please comment above if you think it should be restored or have further information
Limitations
There are two major limitations to the Query Expressions syntax. The first is the loss of support for wildcards and comma-separated range values, and the second is the inability to reference array fields such as dimensions. (SEE CORRECTION HERE UNDER!!!)
Whilst in standard queries you can specify "AA*" or "A,B,C" as criteria, and they will be parsed by Axapta and sent through correctly to the database, these will simply be passed directly through when using the Query Expressions engine. As a result, they will not return the expected results. On a related noted, the use of 'like' is not supported, so there is no way to use wildcards in any form.
Unfortunately, if you wish to filter on array fields in an Axapta table, such as the Dimensions field, there is no way to do so using the Query Expressions syntax. (SEE CORRECTION HERE UNDER!!!)
Correction :
To filter on array fields in an Axapta table you should use the "fieldId2Ext(fieldId,tableIndex)" method. Axapta will not show you IntelliSense help for this function but will still compile it.
Example of use :
queryBuildRange = dsLedgerTrans.addRange(fieldId2Ext(fieldNum(LedgerTrans, Dimension),1));
Dimensions
queryBuildRange.value(strFmt('((Dimension[1] == %1) || (Dimension[2] == "%2"))', "some dim1 value", "some dim2 value"));
You can do the following in Axapta with as
queryBuildRange.value(strFmt('((Dimension == %1) || (Dimension2_ == "%2"))', "some dim1 value", "some dim2 value"));
Have you tried what is entered above? I tried it and I get the dreaded error:
Query extended range failure: Right parenthesis expected near pos 0.
62.58.93.177 01:39, 29 Dec 2005 (PST)
queryValue
add queryValue call to all parameters :
static void Test_QR(Args _args) { Query query = new Query(); QueryBuildDataSource ds= query.addDataSource(tableNum(InventTable)); QueryBuildRange range= ds.addRange(fieldNum(InventTable, DataAreaId)); QueryRun qr; ; query.literals(1); // Add our range range.value(strFmt('(ItemId == "%1")', queryValue('test "number one"'))); //try to uncomment this and you'll receive error //range.value(strFmt('(ItemId == "%1")', 'test "number one"')); qr=new QueryRun(query); while(qr.next()) { print qr.get(tableNum(InventTable)).RecId; } pause; }