Lightswitch Global Variables

Global variables is one of the most important functionality that I use to set the tone of my application.  For example a variable for the current user log-in, a variable for the default branch of the user, and so on and so forth.  In Microsoft Access I use a local table associated with the ACCDB file, in Microsoft Lightswitch that wouldn’t be possible.  But there is a way to declare a global variable, here’s how you’ll do it:

1. Open your application and double click on the Properties item in the logical view of the solution explorer

2. In the Screen Navigation tab of the designer click the Hyperlink “Click here to view application code.”

3. Now type in your Public Global Variables

To access your variables just type, for example, in your code: Me.Application.CurrentUserId.


Software developer living in the Philippines.

Posted in Lightswitch
4 comments on “Lightswitch Global Variables
  1. sethwid says:

    Thanks for this Harold! How do I access these variables in C#? ‘Application’ doesnt have the same meaning in C#

  2. hgminerva says:

    Sorry I am not very good with C#, but below might be the equivalent:

    Public String SampleVariable;

    To access just use the “this” object


  3. sethwid says:

    I wasnt able to access a global from the Application class no matter what I could think of, and trying what you suggested. But thats okay, Im sure there is a way to do it but I ended up doing it a different way.

    I created my own class- Common.UserCode.Globals.cs and ended up with this:

    namespace LightSwitchApplication.UserCode
    public class Globals
    public static string LOCATION_MAP_BASE_URL = “foobar”;

    And can access it anywhere in the application with UserCode.Utils.URLBuilder_Continent();

    Hopefully this helps any other C#ers having the same problem. Cheers Harold!

  4. hgminerva says:

    Very nice, thanks sethwid, this will be very helpful for C# developers.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Harold Glenn P. Minerva
Software Developer / Tech Enthusiast
Living in the Philippines

View Harold Glenn Minerva's profile on LinkedIn


Software Engineer - Seasonal and Range Trading Software. Magenta Trader is a powerful stock market visualization software that increases your probability of trading success.

Software Architect and Founder - is a multi-tenant cloud-based Software-as-a-Service (SaaS) business app that caters to micro, small and medium trading businesses.

CTO and Co-Founder - We give your company the leverage by providing innovative software solutions products such as Point-of-Sales (POS), Financial Information System (FMIS), Payroll and DTR (HRIS), and many more.

%d bloggers like this: