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.


4 thoughts on “Lightswitch Global Variables

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

    Public String SampleVariable;

    To access just use the “this” object


  2. 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!

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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s