Search code examples
c#axaptadynamics-ax-2012aif

How to perform a partial string query on Dynamics QueryService?


I'm writing this code in C# using Dynamics AIF.

How do I perform a partial string query on Dynamics QueryService?

The Dynamics query would be like this:

WHERE %1.Field LIKE '*partialstring*'

This is what I'm doing:

QueryDataRangeMetadata range = new QueryDataRangeMetadata();
range.FieldName = field;
range.TableName = tableName;
range.Enabled = true;
range.Value = string.Format(" LIKE '*{0}*'", id);
query.DataSources[0].Ranges[0] = range;

I thought about this solution because this one works:

range.Value = ">2000";

But not the one using like... Is there any way to solve this? Any workaround?

According to Joris, in this post http://daxmusings.codecrib.com/2013/09/linq-to-ax-example-using-wpf.html you can't perform partial queries on strings using dynamics Linq, I'm having the same problem with the QueryService.


Solution

  • I already got an answer at https://community.dynamics.com/ax/f/33/p/148074/333993.aspx from Denis Macchinetti.

    Answer:

    Denis Macchinetti responded on 29 Dec 2014 10:32 AM

    Hi Eros

    In my opinion, you can use a Dynamic Query.

    Take a look at http://msdn.microsoft.com/en-us/library/gg847959.aspx, Dynamic Query section.

    Practically, create an AOT class that extends the AifQueryBuilder class.

    Then call the QueryServiceClient.ExecuteDynamicQuery method and pass the name of the X++ query class and any query arguments.

    An example is the standard class CustTransQueryBuilder.

    In this way, you can handle the "like" condition inside AX!

    Others link :

    http://blogs.msdn.com/b/axsupport/archive/2012/02/17/calling-the-query-service.aspx

    http://msdn.microsoft.com/en-us/library/gg879657.aspx