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 :
Supply chain | Supply Chain Management, Commerce
Suggested Answer

Advanced query syntax - query as an SQL statement using the finance and operations query language

(0) ShareShare
ReportReport
Posted on by 32

Hello, everyone!

 

I'm trying to understand if it is possible (via the user interface) to query records by the first found value?

 

According to MS documentation SQL statements can be used for advanced filter or sort: Advanced filtering and query syntax - Finance & Operations | Dynamics 365 | Microsoft Learn

 

For example, estimate all ‘Created’ Production orders that have the same Sales order reference number (InventRefId). I'm thinking SQL MIN function…

 

I would set up a batch job where each run would include Production orders with the same reference number only.

  • André Arnaud de Calavon Profile Picture
    307,698 Super User 2026 Season 2 on at

    Hi Ilkka,

     

    Can you tell us what exactly is the business requirement here? What do you mean by the same sales order reference? From where do you get that value? Do you want to run the batch per sales order reference individually?

    If you can clarify the functional process, we can help thinking along with you.

  • Ilkka J. Koivisto Profile Picture
    32 on at

    Hi, André!

     

    Yes, sure, I'll try to explain in more detail, thank you for your response!

     

    There are multiple Sales orders, each with multiple lines, and each line with Reference number (SalesLine.InventRefId) to a Production order (in other words, Marking between sales order line and Production order).

     

    So, there are multiple Production orders with same (Sales order) Reference number (ProdTable.InventRefId). Currently users are manually filtering (Created) Production orders based on the (Sales order) Reference number to estimate those Production orders together on one go. This is because each Production order has a BOM line with a (subcontracting) service item, and estimating the Production orders together groups all selected Production orders on one subcontracting Purchase order.

     

    So, the goal is to have one corresponding subcontracting Purchase order against each Sales order. Users are looking for a way to automating this process of generating the subcontracting Purchase orders.

     

    We can set up recurring batch job to estimate (Created) Production orders but each recurrence should include only Production orders with the same Reference number (ProdTable.InventRefId), and I am not sure if this is possible in standard system.

  • Suggested answer
    Martin Dráb Profile Picture
    241,343 Most Valuable Professional on at

    This isn't something you can do in the query filter value of a field. It needs to be handled by developers of the batch job, who can use things like the GROUP BY clause.

  • Suggested answer
    Aayush Tiwari Profile Picture
    626 on at

    Hello @Ilkka J. Koivisto 

    As Martin mentioned, this will not work in standard advance filter, If this is a critical business requirement & you are looking for a way to automating this process of generating the subcontracting Purchase orders then you have to go with the customization.

     

    Regards

    Aayush Tiwari

  • Ilkka J. Koivisto Profile Picture
    32 on at

    Thank you, @Martin Dráb and @Aayush Tiwari !

     

    I'm just wondering what additional filtering capabilities or benefits “query as an SQL statement” or “SysQueryRangeUtil method” provide compared to the usual matches operator syntax? There must be some reason for having these options as otherwise they would only offer more complex way for writing the (simple) queries.

  • Suggested answer
    Martin Dráb Profile Picture
    241,343 Most Valuable Professional on at

    They indeed can do more than just providing a static value.

     

    SysQueryRangeUtil methods allow you to generate the value at runtime by X++ code. For example, you may generate values taking into account things like the current date or the current user setup

     

    With the expressions, you can do things like writing conditions for multiple fields at once or create conditional joins.

     

    But it doesn't mean that you can do everything there and you'll never need to ask a developer to prepare any query or a view for you.

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 > Supply chain | Supply Chain Management, Commerce

#1
André Arnaud de Calavon Profile Picture

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

#2
Laurens vd Tang Profile Picture

Laurens vd Tang 102 Super User 2026 Season 2

#3
Aayush Tiwari Profile Picture

Aayush Tiwari 56

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans