2

can anyone give me a nudge in the right direction as to how to do an "OR" query via the Query Service?

In order to do an "AND" query I can simply add two (or more) "Ranges" - this sort of jazz:

        // build and add our new filter
        QueryDataRangeMetadata range = new QueryDataRangeMetadata
        {
            TableName = dataSource.Table,
            FieldName = fieldName,
            Value = fieldValue,
            Enabled = true
        };

        dataSource.Ranges[ranges.Length - 1] = range;

..but how does one do an "OR" ??

Jonathan Bravetti
  • 2,228
  • 2
  • 15
  • 29
tigerprawn
  • 63
  • 1
  • 8

3 Answers3

3

OR in AX queries can be made by any of these tree methods:

  1. Adding another query range on the same field
  2. Have a range with comma-separated values
  3. Use a query expression

See this question if the OR involves different tables.

These options should apply Query Service as well.

Community
  • 1
  • 1
Jan B. Kjeldsen
  • 17,817
  • 5
  • 32
  • 50
1

...thanks for the suggestions, but in the end I don't think it's helped me much :-(

1.Adding another query range on the same field

=> unfortunately I need to query on a different field ..essentially "WHERE A=1 or B=2" type thing..

  1. Have a range with comma-separated values

=> unfortunately also doesn't work with separate fields

  1. Use a query expression

=> unfortunately I could not get this to work, and am coming round to the idea that it is not actually a feature the "AX Query Service 2012" (as per title) that is the tech I am working with (looks like it is something within AX??). Note that when defining a Range the "FieldName" property of the QueryDataRangeMetadata instance is required (and no - comma separated field names did not work).

On the plus side I have now got it working :-) ...the way I did it was to add the table twice as two different datasources to the query- seems nasty, but what's a man to do...

thanks again- Oli.

tigerprawn
  • 63
  • 1
  • 8
0

I have used this in the past:

queryBuildRange.value(strFmt('((%1 == %2) || ((%1 == %3) && (%4 == "%5")))',
    fieldStr(InventTable, ItemType),
    any2int(ItemType::Service),
    any2int(ItemType::Item),
    fieldStr(InventTable, ProjCategoryId),
    queryValue("Spares")));

Probably is not the cleanest way to do it but will do the job.