web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Unanswered

Global variables in a single instance codeunit

(0) ShareShare
ReportReport
Posted on by 5

Hi experts! 

I am wondering if there are any recommendations about using global variables in single instance codeunits in Business Central. Generally, in modern object oriented programming defining and using global variablies should be avoided at all costs.

Are there any official guidelines for BC?

Here is an example where it is really tempting to use single instance codeunit global variables: I am using two subscribers - OnValidate Qty on Warehouse Receipt Line (1) and OnValidate Qty on Purchase Line (2). 

(1) should update values on both Warehouse Receipt Line and on Purchase Line.

(2) should update only values on Purchase Line.

The problem is that when I call (1), it triggers my code in subscriber (2) - I don't want to do that. I don't have a handled boolean here in parameters, as those are standard OnValidate triggers. 

What is the best approach? Is using single instance codeunit global variables a no-go here?

I have the same question (0)
  • Marco Mels Profile Picture
    on at

    Hello,

    We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist.  If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    dynamicsuser.net/.../developers

    I will open this up to the community in case they have something to add.

    Thanks.

  • JAngle Profile Picture
    133 on at

    This is worth watching: https://youtu.be/rmdUXtGqYw8

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

News and Announcements

Season of Giving Solutions is Here!

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 1,688

#2
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 784 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 595 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans