Can Flow field be used in Setrange outside the repeat loop
ChatGpt tolder me I cannot compare flowfields in setrange (after using calcfields) like below, is it true or inefficient
salesheader.setrange(Flowfield1, Flowfield2)
If salesheader findset() then
repeat
Until
FlowFields Cannot Be Used in SetRange Filters
FlowFields are calculated fields - they don't exist as physical columns in the database table. They are computed on-the-fly based on their CalcFormula.
Business Central's SQL engine cannot translate FlowField comparisons into WHERE clauses because:
- FlowFields are virtual - there's no column in SQL Server to filter on
- Each record's FlowField value requires a separate sub-query to calculate
SetRangeon a FlowField would need to calculate EVERY record first, then filter - extremely inefficient
Best Answer
-
FlowFields Cannot Be Used in SetRange Filters
is wrong (at least in BC, and I believe even in the latest versions of NAV).
Business Central's SQL engine cannot translate FlowField comparisons into WHERE clauses
is wrong. Reason 1 is plain stupid wrong; reason 2 is no reason for the claim and is not necessarily true; reason 3 is no reason for the claim and is worded in a misleading way. The SQL engine will have a query optimizer and will likely calculate the value for the flowfield only after having rejected records based on other conditions if it is more costly than to evaluate the other conditions.
What is the alternative to filtering on the flowfield? You would have to retrieve data for all candidates, calculate the value of the flowfield so you are able to compare against it in code. So, you are doing the same work, but have to transfer more data from the database.
Unless you have more conditions you need to check in code (i.e. cannot specify as filter expressions) which can be executed more efficiently than calculating the value of the flowfield, letting the SQL engine execute the condition on the flowfield may be more efficient; still costly, but more efficient. In this case you would need to calculate the flowfield with a CalcFields statement, not using the autocalfields feature to possibly gain anything. But you would then need an additional call to the database to get the calcfield value. So, in the end, still unlikely to be more efficient.
0
Answers
-
FlowFields Cannot Be Used in SetRange Filters
is wrong (at least in BC, and I believe even in the latest versions of NAV).
Business Central's SQL engine cannot translate FlowField comparisons into WHERE clauses
is wrong. Reason 1 is plain stupid wrong; reason 2 is no reason for the claim and is not necessarily true; reason 3 is no reason for the claim and is worded in a misleading way. The SQL engine will have a query optimizer and will likely calculate the value for the flowfield only after having rejected records based on other conditions if it is more costly than to evaluate the other conditions.
What is the alternative to filtering on the flowfield? You would have to retrieve data for all candidates, calculate the value of the flowfield so you are able to compare against it in code. So, you are doing the same work, but have to transfer more data from the database.
Unless you have more conditions you need to check in code (i.e. cannot specify as filter expressions) which can be executed more efficiently than calculating the value of the flowfield, letting the SQL engine execute the condition on the flowfield may be more efficient; still costly, but more efficient. In this case you would need to calculate the flowfield with a CalcFields statement, not using the autocalfields feature to possibly gain anything. But you would then need an additional call to the database to get the calcfield value. So, in the end, still unlikely to be more efficient.
0 -
Did you try doing some sample code and than see the result?
Simple piece of AL code like -
Customer.SetRange("No.", 'C10000');
Customer.SetRange("Balance on Date", 0, 20231231D);
if Customer.FindFirst() then
Message(Format(Customer."Balance at Date"));Thanks
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/1 -
Thanks for the answers , yes I did use flow fields on setrange and it worked however when the AI suggest code it always include calfield and flow fields inside the repeat loop so i though i'm missing something - to be fair to ChatGpt above AI statement is given by Claude Opus 4.5 supposed to be the latest and greatest :) …but one can argue if the models are trained on human forums and internet posts then there is some previous knowledge gap expressed and model just picked up that. interesting times
0 -
Ya I agree that's why I said - Did you try this? 😊
CALCFIELDS are needed in Repeat Until because the value is continuously changing inside the loop and system needs to recalculate and give the correct data.
Thanks
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 327 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions

