ArcherPoint Dynamics NAV Developer Digest - vol 240
The NAV community, including the ArcherPoint technical staff, is made up of developers, project managers, and consultants who are constantly communicating, with the common goal of sharing helpful information with one another to help customers be more successful.
As they run into issues and questions, find the answers, and make new discoveries, they post them on blogs, forums, social media...so everyone can benefit. We in Marketing watch these interactions and never cease to be amazed by the creativity, dedication, and brainpower we’re so fortunate to have in this community—so we thought, wouldn’t it be great to share this great information with everyone who might not have the time to check out the multitude of resources out there? So, the ArcherPoint Microsoft Dynamics NAV Developer Digest was born. Each week, we present a collection of thoughts and findings from NAV experts and devotees around the world. We hope these insights will benefit you, too.
Kyle shares some developer funnies: Happy Friday!
Which Code Snippet is Better?
Matt T ponders: “Just something to make us think. Which one of these code snippets is better?”
FOR i := 1 TO 10 DO BEGIN
array[i] := i;
array := 1;
array := 2;
array := 3;
array := 4;
array := 5;
array := 6;
array := 7;
array := 8;
array := 9;
array := 10;
Tom Hunt gives his two cents: “It would be the FOR loop, since it's easier to modify later. At least, that's my vote. Although my opinion could change if I had more context.”
Ian chimes in: “I'd go with the loop, too. Less to write, same result.”
Jon says: “My vote is the loop since it's extendable and scalable.”
Kyle adds: “It depends. If any one of the ten values might change in the near future, then you have to remove the FOR loop and replace it with the second choice.”
Saurav: “FOR i := 1 TO 10 DO
array[i] := i;”
Matt T then asks: “Which one runs faster?”
Kyle states: “The ten sequential sets run faster than the loop.”
Matt T confirms: “You, sir, are correct. This weird example is meant to point out a couple of things, one being that there isn't always a ‘better’. ‘Better’ depends on what you are considering in your design. Readability? Scalability? Probably the loop is better. Performance? I'm pretty sure for most of us, the thought of designing for performance doesn't often enter our minds. Most of the time it doesn't matter because modern NAV is fast. Who cares if a loop takes 3x as long to execute? Little things add up, though. Who considers the parameters you can pass to FINDSET for performance? Who knew there were parameters? SETRANGE performs better than SETFILTER. Things we just don't think about that have an impact on performance.”
Jon adds: “I failed to ask ‘Why?’ and define ‘better.’ Doh! Thanks, Matt.”
Consulting Corner: Production Planning
Gwen wants to know: “Can someone explain to me the business logic that allows an unreleased Sales Order to show up in the Calc. Plan for production? Why does the system recommend that one begins production to fulfill an order that is not yet released? That feels icky to me.”
Dave W responds: “Hi Gwen, it is called planning, not doing. If you think about it, the other major demand driver for planning is a forecast, which is even more scary because it's probably a sales guy’s overly optimistic view of the world. Most clients I work with have no problem with this approach.”
He adds: “The other thing to consider is if the client’s product is stock or made to order. If made to order, the other tool you might want to review is the Order Planning worksheet, which does show the document status.”
Gwen: “Thank you much Dave!”
Brendon: “Forecasting off sales guys... that's scary!”
Tim: “Can someone create a mod that pays Commission off of our Forecast? I'm thinking that would really make things easier for all.”
Gwen: “Now that I have your requirement, I'd be happy to solution this for you.”
Matt T: “That's easy. It's just one line of code to change.
//CommissionJournalLine.Amount := CustomerLedgerEntry.Amount;
CommissionJournalLine.Amount := Opportunity.Amount;”
Gwen: “LOL! Love it.”
If you are interested in NAV development, be sure to see our collection of NAV/BC Development Blogs.
Read the "How To" blogs from ArcherPoint for practical advice on using Microsoft Dynamics NAV and Dynamics 365 Business Central.