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 :
Small and medium business | Business Central, N...
Answered

Passing on API-filters to a query

(4) ShareShare
ReportReport
Posted on by 112
Hello, 

I'm working on an API to get the stock of an item variant at a certain location. 
As there are some additional data from the item and item variant table I've created the following structure:

API-Page 1 based on item - table
                additional fields... 
                Subpage (Link: Item No):
                API-Page 2 based on custom item variant - table
                               additional fields...
Subpage (Link: Item No, Variant No):
API-Page 3 based on temporary table filled by a Query summing up the remaining quantities

                fields: item, item variant, location, Sum(Quantity)
 
The OnOpenPage-Trigger of API-Page 3 opens the query and inserts into the temporary table. 

My challenge: Of course I want to apply the filters to the query before opening it to speed it up. This would be the location (no field in the tables of pages 1 and 2) as well as "indirect" filters e.g. on the item-description on API-Page 1.

Is there any way to get them? Or is there another best pratice?

I'm looking forward to your great ideas and suggestions! :-)

Thanks in advance!


 
I have the same question (0)
  • Suggested answer
    Ramesh Kumar Profile Picture
    7,529 Super User 2025 Season 2 on at

    API-Page 1: Allow the user to set filters (such as item description and location). API-Page 2: Show item variant details based on the item, and allow users to set additional filters if needed. API-Page 3: Sum the quantities in a temporary table based on the filters applied from the previous pages. Ensure that you're passing necessary data between pages using global variables or page context, and always aim to reduce the amount of data being processed by filtering early in the process.

    https://www.rapidionline.com/product-updates/api-pages-in-microsoft-dynamics-365-business-central

     

    Thanks, Ramesh

    If this was helpful, please check the "Does this answer your question?" box and mark it as verified.


     
  • Suggested answer
    YUN ZHU Profile Picture
    95,752 Super User 2025 Season 2 on at
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    20,895 Super User 2025 Season 2 on at
    To apply API filters dynamically to your query before execution, consider using SetFilter or SetRange in the OnOpenPage trigger of API-Page 3. Since location isn't directly available in Pages 1 and 2, try passing it as a parameter from the API request and use Rec.GetFilters to retrieve indirect filters like Item Description. If API pagination is enabled, ensure that filters propagate properly across subpages. Alternatively, using a custom AL function to collect and apply filters before executing the query can improve performance
  • Verified answer
    Chris Brill Profile Picture
    112 on at
    Thanks to you all for your replies.

    With your help I was able to find a solution. As this was my first BC-API it was actually pretty simple: I was not expecting that a simple GetFilters (within the right trigger) on Page 3 would actually return all filters but that I had to take care of passing them on myself. 

    Thanks, 
    Christopher

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 > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,132

#2
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 675 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 665 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans