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 :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Adding enum value in query range

(0) ShareShare
ReportReport
Posted on by 35

Hi all,

I'm trying to build a very simple query to filter a form on 3 fields. I placed my code in the form datasource in the executeQuery() method before super().
I'm having a hard time adding a FieldEnum to the range with it's value. 
In my code below I have 3 variations I tried to no avail. I would greatly appreciate some help from the experts. Thanks very much.

Error message reads : 
The expression '**insert one of the variations** cannot be resolved to a know type
Methods can only be called on classes and tables. This expression is of type 'int'



[Form]
public class TestWarehouseStockIssuer extends FormRun
{

Query query = new Query();

[DataSource]
class TestWarehouseStock
{
public void executeQuery()
{
QueryBuildDataSource qbds = query.dataSourceTable(tableNum("TestWarehouseStock"));

qbds.addRange(fieldNum(TestWarehouseStock, PurchId));
qbds.addRange(fieldNum(TestWarehouseStock, PurchReqId));

**Below are the 3 variations**

//qbds.addRange(fieldNum(TestWarehouseStock, Status).value(SysQuery::value(TestMIMStatus::Available)));

//qbds.addRange(fieldNum(TestWarehouseStock, Status).value(QueryValue(TestMIMStatus::Available)));

//qbds.addRange(fieldNum(TestWarehouseStock, Status).value(enum2Int(MIMStatus::Available)));

super();
       }

   }

}
 

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

    SysQuery::value(TestMIMStatus::Available) and queryValue(TestMIMStatus::Available) are both correct (and doing exactly the same thing, because queryValue() does nothing more than calling SysQuery::value(). I think that the error suggests that the enum or the enum element doesn't exist, or it isn't visible, because it's defined in a package that you don't refer to from your package.

    You can easily test this theory. Use this assignment:

    TestMIMStatus test = TestMIMStatus::Available;

    If it fails to compile, it'll prove that the problem is in the enum and it has nothing to do with query ranges.

    By the way, if your code worked, it would added extra identical ranges everry time when the query executes. If you always want to see available records only, simply add the range just once in init().

  • Corne Smith  Profile Picture
    35 on at

    Of course it's after I make a post that I find the solution.

    Solution:

    qbds.addRange(fieldNum(MIMWarehouseStock, Status)).value(SysQuery::value(MIMStatus::Available));

    Kind Regards

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

    Aha, a missing parenthesis.

    Please don't overlook my remark about the why you shouldn't add this range in executeQuery().

  • Community member Profile Picture
    2 on at
    Hello, I think to resolve this issue, you need to ensure that the field enumeration value is correctly passed to the addRange() method. Here's an updated version of your code that should work: merge fruit
    csharp
    [Form]
    public class TestWarehouseStockIssuer extends FormRun
    {
        Query query = new Query();
        [DataSource]
        class TestWarehouseStock
        {
            public void executeQuery()
            {
                QueryBuildDataSource qbds = query.dataSourceTable(tableNum(TestWarehouseStock));
                qbds.addRange(fieldNum(TestWarehouseStock, PurchId));
                qbds.addRange(fieldNum(TestWarehouseStock, PurchReqId));
                qbds.addRange(fieldNum(TestWarehouseStock, Status)).value(enum2int(enumNum(MIMStatus), MIMStatus::Available));
                super();
            }
        }
    }

    In this code, the enum2int function is used to convert the enumeration value MIMStatus::Available to its corresponding integer value. The enumNum function retrieves the enumeration table for MIMStatus, and fieldNum retrieves the field number for the Status field. Finally, the value method is called on the Range object to set the value for the range using the converted enumeration value.
  • Martin Dráb Profile Picture
    237,882 Most Valuable Professional on at
    I don't see any benefit in using enum2int(enumNum(TestMIMStatus), TestMIMStatus::Available) instead of simple queryValue(TestMIMStatus::Available).

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 565 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 450 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans