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)

A basic example of populating a form based on values in two fields from the same table.

(0) ShareShare
ReportReport
Posted on by

I have looked everywhere, and there are so many different ways to do this, but I cannot find a complete example. I know it's a rookie question, and I apologize. I have also looked through the AOT, but I got so many search results it was hopeless.

So, I have a form. I have added a data source, and am modifying the executequery() method. I want the form to display records if FieldA (NoYes enum) is set to 1, and when FieldB (a TableGroupAll enum) is set to All (aka, 2).

So, to do it for ONE field, I do this (and it works):

 

public void executeQuery()
{

QueryBuildRange testQBR;

;

testQBR = this.query().dataSourceName('NameOfMyDataSource').addRange(fieldnum(NameOfMyDataSource,FieldA));

testQBR.value(queryvalue(1));

super();

}

Easy. But I have looked and looked and looked and could not find any example that specifically states how to do this with two fields. I know it has to be simple, and I'm terribly embarrassed to be asking.

 

*This post is locked for comments

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

    You are almost there.

    public void executeQuery()

    {

    QueryBuildRange testQBR;

    QueryBuildRange testQBR2;

    ;

    testQBR = this.query().dataSourceName('NameOfMyDataSource').addRange(fieldnum(NameOfMyDataSource,FieldA));

    testQBR2 = this.query().dataSourceName('NameOfMyDataSource').addRange(fieldnum(NameOfMyDataSource,FieldB));

    testQBR.value(queryvalue(1));

    testQBR2 .value(enumName::All);

    super();

    }

  • Community Member Profile Picture
    on at

    Wow, I knew it was simple, but not THAT simple ;)

    I do keep getting an error that the enum does not exist, however, when I execute the last line.

  • Community Member Profile Picture
    on at

    Yeah..it is simple.

    Check the Table:FiledB enum type property at table level, and use the same enum name.

    Check in the enums section AOT if it exists. It shoud exist as the table field is already based on it.

  • Daniel Weichsel Profile Picture
    on at

    Use TableGroupAll::All in the second .value call (enumName was just used as a placeholder in the example).

  • Community Member Profile Picture
    on at

    I already tried this:

    QBR2.value(TableGroupAll::All);

    And it tells me that "value" is not compatible with the required type.

    I then tried this:

    QBR2.value(queryvalue("All"));

    That compiles. Then I use this handy-dandy piece of code:

    info(QBR2.toString());

    and it shows "FieldB = 2", which is correct.

    However... it does not seem to be working, in that the records that have FieldB set to 2 are not displaying on the grid (the ones that have FieldA set to 1 do display). I think I know why that isn't working, however. I am on the VendTable form on a new tab I have created. I want values to display on my new grid even if they're not linked to that specific vendor (ie: TableGroupAll is set to "All"). Since they're not linked, no display :(

  • Suggested answer
    Joris dG Profile Picture
    17,775 on at

    Keep in mind that adding the range in executeQuery will keep adding the range over and over again every time the query is executed.

    Consider using SysQuery::findOrCreateRange which will either return the existing range, or add a new one for you.

  • Verified answer
    Joris dG Profile Picture
    17,775 on at

    Also, try:

    QBR2.value(queryValue(TableGroupAll:All));

    which avoids hardcoding your filter with a string value.

  • Community Member Profile Picture
    on at

    I have done as suggested, and everything compiles. Form opens, but am not seeing what I expect. I'm going to submit another question, as I believe my problem goes further back.

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