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)

Query From One String Edit to Multiple Grid Fields

(0) ShareShare
ReportReport
Posted on by

1460.Capture.JPG

MAC ADRESS will be entered by the user ... Upon Clicking Search , I want the Query to be used on both Fields Marked in Red...

I am using the code below..

   // add range Mac Address1
         AXW_SerialNumberTable_q.dataSourceName(AXW_SerialNumberTable_ds.name())
       .addRange( fieldNum(AXW_SerialNumberTable ,MainMacAddress))
       .value(  MacAddress.text()  );

         // add range Mac Address2 -51
         AXW_SerialNumberTable_q.dataSourceName(AXW_SerialNumberTable_ds.name())
       .addRange( fieldNum(AXW_SerialNumberTable ,SubMacAddress))
       .value(  MacAddress.text()  );

P.S   This is not Working Properly , I reckon both these blocks of code need to be written as One ..

 perhaps I need to change , fieldNum.....  Is there like field Range or something ...

Please help me fix the code...

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    Your requirement ("I want the Query to be used on both Fields Marked in Red") isn't specific enough, because the ranges can be "used" in different ways. The fact that you don't like the current behavior suggests that you want to one particular way, which isn't the default one.

    If you look at the resulting SQL query (you should get used to doing it, because otherwise you'll have the same problems with debugging all the time), you'll see that you've successfully added ranges for both fields, but they're combined with AND. I guess you want OR instead.

    One option is using expressions in query ranges to create the combined range with OR. Alternatively you could put MAC addresses to a separate table (with two lines if one entity has two addresses) and add an exists join with a single range.

  • yasu Profile Picture
    on at

    In case of OR ... Can you please fix this code????    

    I have used query range , e-g in case to Order Id from / Order Id to ........ Date from / Date to

    but I dont know how to use in this case.....

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

    I suggested two possible solutions. Does it mean that you want the first one (and didn't try it by yourself), or that you overlooked the part with solutions?

  • yasu Profile Picture
    on at

    I need the solution so desperately why would I overlook your suggestions   ?????    

    I like the first one , Obviouly I tried it , but it didn`t work so thats why I am asking again ..  :(

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

    I obviously can't know things that you don't tell me, such as that you read the solutions and which one you've decide to implement.

    Can you please explain the problem with your attempt in better detail? I can't fix it if all I know is "it didn`t work".

  • yasu Profile Picture
    on at

    I said the First Solution ...These 2 add ranges below bascially have and AND connection right ... How can I change then into an OR connection..

       // add range Mac Address1

         AXW_SerialNumberTable_q.dataSourceName(AXW_SerialNumberTable_ds.name())

          .addRange( fieldNum(AXW_SerialNumberTable ,MainMacAddress))

          .value(  MacAddress.text()  );

            // add range Mac Address2 -51

          AXW_SerialNumberTable_q.dataSourceName(AXW_SerialNumberTable_ds.name())

          .addRange( fieldNum(AXW_SerialNumberTable ,SubMacAddress))

          .value(  MacAddress.text()  );

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

    This is your original code without any change, isn't it? Where is your code for the first of my solutions, which you said you tried? It seems you didn't try it after all and gave me wrong information.

    Let me teach you what you should have done:

    1. Read what people tell you. You'll see that one of the suggested solutions is "One option is using expressions in query ranges to create the combined range with OR".
    2. If you have no idea what it means, use a search engine to find more information. For example, put ax expressions in query ranges to Google.
    3. You'll fine a documentation page called Using Expressions in Query Ranges - read it. You'll see it demonstrates exactly what you need - ranges for two fields combined with OR.
    4. Write your own solution based on the documentation.
    5. If you get into a problem that you can't resolve, go back to the forum and don't forget to provide your code and information about your problem, such as what error are you getting.
  • Suggested answer
    Chaitanya Golla Profile Picture
    17,225 on at

    Hi,

    Use the following code(I don't have your objects couldn't compile or test it, may require slight modifications)

    QueryBuildDataSource qbds;

    qbds = AXW_SerialNumberTable_q.dataSourceName(AXW_SerialNumberTable_ds.name());

    qbds.addRange(fieldNum(AXW_SerialNumberTable, MainMacAddress)).value(strFmt('((%1.%2 == %4) || (%1.%3 == %4))',

                 qbds.name(),

                 fieldStr(AXW_SerialNumberTable, MainMacAddress),

                 fieldStr(AXW_SerialNumberTable, SubMacAddress),

         queryvalue(MacAddress.text())));

    Please let us know if anything is missing and consider the suggestions/inputs provided by Martin.

    Thanks,

    Chaitanya Golla

  • yasu Profile Picture
    on at

    Thank you  Chaitanya Golla

    The code compiles Fine ...

    but I get this error up Upon execution of the query .....

    Query extended range failure: Syntax error near 46.   :(

  • yasu Profile Picture
    on at

    I tried the below   code aswell ..but This has syntax error.. doesnt compile

          AXW_SerialNumberTable_q.dataSourceName(AXW_SerialNumberTable_ds.name())

          .addRange( fieldNum(AXW_SerialNumberTable ,MainMacAddress ))

          .value(  QueryValue( "((MainMacAddress=" MacAddress.text()") || (SubMacAddress = "MacAddress.text()"))"  ) );

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