locked
Lightswitch 2013 How to create and set an initial Global Variable and then use that Variable for filtering data in screens throughout project? RRS feed

  • Question

  • Howdy, I have Lightswitch 2013.  What is best way to create and set an initial Global Variable? Then I want to use that Global Variable for filtering data queries of online SQL database?  For example, if I want to create and set an autocomplete search box on my first screen and then use that specific field in all future queries and all screens?  I have my project about 90% complete (but the hard 10% is left) and I need the exact steps to create and set the Global Variable.  Don't assume I know anything.  Thanks.
    Tuesday, June 9, 2015 4:10 PM

Answers

  • There are a couple of ways to do this, but the easiest might be to do the following:

    1. In the _created() method of the home screen set the global variable as a property on the myapp global object, for example: myapp.MyGlobalVariable = 10;
    2. On every screen that you need to use that you can then declare a screen variable to use as parameters to the queries and set the value for that screen variable in the _created() method of that screen. For example: screen.MyVariable = myapp.MyGlobalVariable;

    Hope that makes sense.


    Regards, Xander. My Blog

    • Proposed as answer by ADefwebserver Wednesday, June 10, 2015 4:33 PM
    • Marked as answer by Angie Xu Monday, June 22, 2015 9:08 AM
    Wednesday, June 10, 2015 2:34 AM

All replies

  • There are a couple of ways to do this, but the easiest might be to do the following:

    1. In the _created() method of the home screen set the global variable as a property on the myapp global object, for example: myapp.MyGlobalVariable = 10;
    2. On every screen that you need to use that you can then declare a screen variable to use as parameters to the queries and set the value for that screen variable in the _created() method of that screen. For example: screen.MyVariable = myapp.MyGlobalVariable;

    Hope that makes sense.


    Regards, Xander. My Blog

    • Proposed as answer by ADefwebserver Wednesday, June 10, 2015 4:33 PM
    • Marked as answer by Angie Xu Monday, June 22, 2015 9:08 AM
    Wednesday, June 10, 2015 2:34 AM
  • Thanks.  I will try that later today.
    Wednesday, June 10, 2015 4:28 PM
  • Found a way to do what I wanted without a Global Variable.  Thanks anyway.  Will keep your answer for when I next need to do this.
    Thursday, June 11, 2015 2:19 AM