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

How the X++ query with IN looks like ?

(0) ShareShare
ReportReport
Posted on by 309

Hi guys,

May I ask, if I want to query using X++ with multiple string, just like IN clause in SQL Server, can I do that ? and what is look like ?

For example I want to query SalesTable, and I have a condition whether my source provide me a Sales Order Number, or not, and also possible the Sales Order Number provided is multiple. 

Can we do it in single query ?

FYI, I'm using "select query" not the QueryBuilder.

Thanks,

I have the same question (0)
  • Suggested answer
    Mohit Rampal Profile Picture
    12,565 Moderator on at

    Hi Axel, As per this article IN operator is supported in F&O. This is interesting as I think it was not supported in previous versions. Let us know if it works for you.

    blogs.msdn.microsoft.com/.../

  • Axel Cage Profile Picture
    309 on at

    Hi Mohit,

    Thanks, Upon trying (also searching), it looks like it is only support Enum Values as the example. I have error when using to check my table which has multiple customer account, with something like this : 

    Container    conCustomer;
    while select CustAccount from MyTableLine group by CustAccount 
        where MyTableLine.Number == _Number 
        {
            conCustomer  = [MyTableLine.CustAccount];
        }
        
    while select MySecondTable where CustAccount in conCustomer
    

    The editor already threw error saying Types ‘str’ and ‘container’ are not compatible with operator ‘in’.

    This is also mentioned in Martin Drab's blog : https://dev.goshoom.net/2018/12/in-operator-in-d365fo/

    Thanks.

  • Mohit Rampal Profile Picture
    12,565 Moderator on at

    Thanks for sharing the link. Is there any reason you are using select query instead of QueryBuilder.

  • Suggested answer
    Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    Use a query object and add a range for each value. For example:

    Query query = new Query();
    QueryBuildDataSource salesTableDs = query.addDataSource(tableNum(SalesTable));
    salesTableDs.addRange(fieldNum(SalesTable, SalesId)).value(queryValue('SalesId1'));
    salesTableDs.addRange(fieldNum(SalesTable, SalesId)).value(queryValue('SalesId2'));
    
    QueryRun qr = new QueryRun(qr);
    while (qr.next())
    {
        SalesTable salesTable = qr.get(tableNum(SalesTable));
    }

  • Axel Cage Profile Picture
    309 on at

    Hi Martin,

    Which mean there is no other solution except QueryBuilder ?

    Reason I hesitant to use it, is only for standard since the current code I'm handling is using Sql query.

    Thanks

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

    You should stop hesitate and start using it, because it allows you to generate queries in a dynamic way, instead of having the structure hard-coded in X++ select statements. It's exactly what you need, IMO.

    It's not the only way - you could also use SysDA framework (which is better for performance but awkward to use).

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 663 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 348 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans