Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

How to pass Where Clause (Conditions) in Select Statement generating dynamically from some parameter table in X++ code

Posted on by 135

I am working in a functionality where i have to generate the where clause dynamically and pass it on the while select loop to execute the further logic.

Below is the complete steps :- 

1. I have a parameter form , where user will define the validation fields and conditions with AND /OR and multiple lines 

2. I have to read the parameter records and looped it and create a where clause reading the fields validation from the parm table.

It will look like this .

Parameter Forms 

3487.png

Parm table has below condition 

condition = Mycustomtable.Field1 >= today &&  Mycustomtable.DeliveryFromDate >=today()

I have below code and  want to create the where clause reading the parm records and apply condition 

While Select MyCustomtable where condition *******(Here parm table condtion should apply automatically )

{

//Do something

}

Note :- Need help to apply condition on while loop and that condition should be created in the runtime and applied on the run time 

Any help would be appreciated !

.

  • Sergei Minozhenko Profile Picture
    Sergei Minozhenko 23,089 on at
    RE: How to pass Where Clause (Conditions) in Select Statement generating dynamically from some parameter table in X++ code

    Hi Binay,

    There are already some examples in the documentation. Basically you need

    1. Create query object

    2. Add data sources and ranges

    3. Create QueryRun object

    4. Iterate through records using queryRun.Next

    docs.microsoft.com/.../how-to-create-queries-by-using-x  - in the first section you can find how to create query from x++, the second section contains an example how to use while (qr.next() to iterate through select result)

    docs.microsoft.com/.../using-expressions-in-query-ranges - how to create complex ranges (like or conditions for different fields)

    I'm not sure if there is a similar code related to your task can be found in the system. But you can search in classes by text "QueryRun", there are a lot of different examples.

  • BINAY KUMAR PANDEY Profile Picture
    BINAY KUMAR PANDEY 135 on at
    RE: How to pass Where Clause (Conditions) in Select Statement generating dynamically from some parameter table in X++ code

    Can you please help me with any sample code in the system where similar thing working.

  • Suggested answer
    Sergei Minozhenko Profile Picture
    Sergei Minozhenko 23,089 on at
    RE: How to pass Where Clause (Conditions) in Select Statement generating dynamically from some parameter table in X++ code

    Hi Binay,

    If you need to generate select statements dynamically based, you need to use Query objects.

    docs.microsoft.com/.../query-object-model

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans