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

This question is answered

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.

 

Verified Answer
  • 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();

    }

  • Also, try:

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

    which avoids hardcoding your filter with a string value.

All Replies
  • 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();

    }

  • 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.

  • 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.

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

  • 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 :(

  • 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.

  • Also, try:

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

    which avoids hardcoding your filter with a string value.

  • 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.