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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Using wildcards in queryvalue

(0) ShareShare
ReportReport
Posted on by

Hi all

I have made a query and I want to pass some wildcards as '*' and '?' in the queryvalue. But when I use one of these wildcards and prompt the QueryRun, I can see that a backslash is being added to the queryvalue, why?

Here is an example for ItemIdMatrix value:

backslash-query.png

while select documentTypeEmailMatrix
        order by Priority
        where   documentTypeEmailMatrix.DocumentType == _docType
        &&      documentTypeEmailMatrix.IsDefault    == false
    {
        query = new Query();
        qbd = query.addDataSource(TableNum(NCEmailMatrixTmp));


        qbr = qbd.addRange(FieldNum(NCEmailMatrixTmp, PostalCode));
        qbr.value(queryValue(documentTypeEmailMatrix.PostalCode));

        qbr = qbd.addRange(FieldNum(NCEmailMatrixTmp, PostalCode));
        qbr.value(queryValue(''));

        qbr = qbd.addRange(FieldNum(NCEmailMatrixTmp, Id));
        qbr.value(queryValue(documentTypeEmailMatrix.Id));

        qbr = qbd.addRange(FieldNum(NCEmailMatrixTmp, Id));
        qbr.value(queryValue(''));

        qbr = qbd.addRange(FieldNum(NCEmailMatrixTmp, JobCode));
        qbr.value(queryValue(documentTypeEmailMatrix.JobCode));

        qbr = qbd.addRange(FieldNum(NCEmailMatrixTmp, JobCode));
        qbr.value(queryValue(''));

        qbr = qbd.addRange(FieldNum(NCEmailMatrixTmp, ItemId));
        qbr.value(queryValue(documentTypeEmailMatrix.ItemIdMatrix));

        qbr = qbd.addRange(FieldNum(NCEmailMatrixTmp, ItemId));
        qbr.value(queryValue(''));
        
        qr = new QueryRun(query);        
        qr.prompt();
        
        while (qr.next())
        {

           qr.setRecord(emailMatrixTmp);
           return documentTypeEmailMatrix;
        }

    }


*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    Hi Crispin,

    Thanks for your response.

    But it doesn'r give me the right answer.

    When I delete the backslash from the query value, it comes with the right result.

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    What exactly did you do when you "used one of these wildcards"? How did you set the range value?

  • Verified answer
    Rohin Profile Picture
    4,624 on at

    Hi Mahyar,

    Sorry if i am getting wrong to you , you want to avoid backslash in query right ?? if so , To do a filter with wild card, you can use SysQuery::valueLikeAfter(). have you tried below code :

    qbr.value(sysQuery::ValueLikeAfter("your range value");

  • Community Member Profile Picture
    on at

    Hi Martin

    I have a string field where I enter the range value  for ItemIdMatrix. When I debug through the code I can see that queryvalue for ItemIdMatrix is the value I entered. But when I prompt the QueryRun I see a backslash added in front of the wildcard. 

    backslash-query-2.png 

  • Community Member Profile Picture
    on at

    Hi Visvash

    Thanks :) that was exactly what I needed.

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    Aha, I see. You asked AX to look for a specific item ID (containing a special character), but then you somehow expect something else and you're surprised when you get the right result. Namely you ask AX to find an item called FV47001-*, which is what happens. But for some reason, you thought that AX would not look for item FV47001-*; you want it to look for items with ID starting with FV47001-, which is something completely different. That would be wrong result when looking for the value "FV47001-*".

    Also, the value is escaped because you put it into your code. That's what queryValue() does.

    It seems that your field isn't an item ID, it's a query criteria. You should name your fields according their contents.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans