web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
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 311

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,

  • Suggested answer
    Mohit Rampal Profile Picture
    12,573 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
    311 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,573 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
    241,467 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
    311 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
    241,467 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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 544 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 347 Super User 2026 Season 2

#3
CU-1234529-002 Profile Picture

CU-1234529-002 197

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans