web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to perform a partial string query on Dynamics QueryService?

(0) ShareShare
ReportReport
Posted on by

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.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Denis Macchinetti Profile Picture
    16,444 on at
    RE: How to perform a partial string query on Dynamics QueryService?

    Hi Eros

    In my opinion, you can use a Dynamic Query.

    Take a look at msdn.microsoft.com/.../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 :

    blogs.msdn.com/.../calling-the-query-service.aspx

    msdn.microsoft.com/.../gg879657.aspx

  • Community Member Profile Picture
    on at
    RE: How to perform a partial string query on Dynamics QueryService?

    Thanks for your answer. I was trying to avoid creating a query inside AX, is it really the only option?

  • Denis Macchinetti Profile Picture
    16,444 on at
    RE: How to perform a partial string query on Dynamics QueryService?

    As per my knowledge... yes

  • Community Member Profile Picture
    on at
    RE: How to perform a partial string query on Dynamics QueryService?

    Denis, I wasn't able to find any example with extending AifQueryBuilder and using select. All examples I found were using QueryRun, QueryBuildDataSource, QueryBuildRange, etc. Could you provide me a link or a snippet on how to do that? Thanks.

  • Suggested answer
    Denis Macchinetti Profile Picture
    16,444 on at
    RE: How to perform a partial string query on Dynamics QueryService?

    Hi Eros

    You can achieve your goal using the LIKE keyword with Query objects.

    Take a look to this old thread community.dynamics.com/.../138167.aspx

    Practically, you can use SysQuery::ValueLikeAfter(...) or SysQuery::ValueLike(..)

    Happy new year!

  • Community Member Profile Picture
    on at
    RE: How to perform a partial string query on Dynamics QueryService?

    Thanks, right after I posted I found that method!

    This is what I ended up doing:

    SysQuery::findOrCreateRange(taxTableDs, fieldNum(TaxTable, TaxName))
            .value(SysQuery::valueLike(this.getArgs().parmDescription()));


    Thanks again!

  • Suggested answer
    Randy33 Profile Picture
    47 on at
    RE: How to perform a partial string query on Dynamics QueryService?

    Joris,

    Below shows how to query for substrings (similar to an SQL LIKE statement).  Also...this requires no modification to the AOT.  Can build the query completely in the client.  

    QueryDataRangeMetadata range = new QueryDataRangeMetadata();

    range.FieldName = field;

    range.TableName = tableName;

    range.Enabled = true;

    range.Value = "*" + "my_substring" + "*"; //★★★ Use asterisk as wildcard.  Similar to percentage signs in SQL LIKE().  

    query.DataSources[0].Ranges[0] = range;

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 4

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#3
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans