Open Forum

Like what you see? Discover the benefits of the NAVUG Community. Learn More

Developers: Functions - Local or Global?

  • 1.  Developers: Functions - Local or Global?

    Posted 8 days ago
    NAV now defaults Object functions you create to be local scope. Assuming I only need them to be local scope, are there any non-obvious ramifications surrounding letting them be local that I should be aware of, say with respect to upgrading in the future, or anything else?

    We are on premise with NAV 2016 and may upgrade to NAV 2018 within the next year or so.

    Thanks,

    ------------------------------
    Michelle Baer
    Programmer / Analyst
    California Chamber of Commerce
    Sacramento CA
    ------------------------------


  • 2.  RE: Developers: Functions - Local or Global?

    SILVER CONTRIBUTOR
    Posted 7 days ago

    Hi Michelle,

    From NAV 2015 onwards, Microsoft has change function's default behavior as local.

     

    Normally in general coding, it is best practice to declare a function as a local function where only within the scope this function can be access. However with earlier versions of Microsoft Dynamics NAV, Microsoft has set this to global, That means from anywhere you can call the functions.

     

    Function's default behavior is based on codeunit Subtype

     

    If the subtype is,

    • Normal à Functions will be local by default
    • Test à functions will be Global by default
    • TestRunner à  Functions will be local by default
    • Upgrade à Functions will be local by default

     

    There will not be any impact when you will upgrade from NAV 2016 to NAV 2018.



    ------------------------------
    Ritu Sood
    All E Technologies Inc.

    ------------------------------



  • 3.  RE: Developers: Functions - Local or Global?

    TOP CONTRIBUTOR
    Posted 7 days ago
    To put it simply--no, there are no concerns about leaving your functions local. As Ritu said, this is best practice.
    If when creating your function you know you will be referring to it from another object, then make it global. Otherwise, just leave it local. You'll know when you need a function to become Global later because you'll be in a different object and you won't have access to the function you need. At that point, you change the function to global.

    ------------------------------
    Greg Enns
    ERP Coordinator
    Technical Prospects
    Kaukauna WI
    ------------------------------