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();
       }

   }

}
 

  • Martin Dráb Profile Picture
    231,801 Most Valuable Professional on at
    Adding enum value in query range
    I don't see any benefit in using enum2int(enumNum(TestMIMStatus), TestMIMStatus::Available) instead of simple queryValue(TestMIMStatus::Available).
  • Community member Profile Picture
    2 on at
    Adding enum value in query range
    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
    231,801 Most Valuable Professional on at
    RE: Adding enum value in query range

    Aha, a missing parenthesis.

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

  • Corne Smith  Profile Picture
    35 on at
    RE: Adding enum value in query range

    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

  • Suggested answer
    Martin Dráb Profile Picture
    231,801 Most Valuable Professional on at
    RE: Adding enum value in query range

    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().

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,933 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,801 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans