locked
How do I persist a (non-user) variable/ entity across screens for filtering purposes RRS feed

  • Question

  • I have a football tipping application (Lightswitch 2012 - VB) and I'm trying to set it up so the user can filter a number of screens according to their choice of a number of different options (eg home team, away team, venue, round etc) 

    I've set up a "UserChoices" entity - with all those options as relationship entities that the user can choose on a "Choices" screen.

    However, then when I try to use these as a filter for other entities I run into trouble. Going to the 'Games' entity for example I've tried this simplified version:

    Private Sub Games_Filter(ByRef filter As System.Linq.Expressions.Expression(Of System.Func(Of Game, Boolean)))
                ' filter = Function(e) e.IntegerProperty = 0
                Filter = Function(Fi) Fi.HomeTeam.FullName = "Dallas Cowboys"
            End Sub

    ... with the intent that "Dallas Cowboys" will be replaced with the persistent variable but that's where I'm running out of ideas.

    For starters though, that filter doesn't work - it produces a Games ListDetails screen full of red X's and a message telling me "Unable to load data. Please check your connection and try loading again" (All other screens load just fine, there is data with that team name and removing the filter makes this screen work just fine)

    So questions 1) Any ideas on the filter itself 2) Any help on how I actually replace the hard coded team name with the selected variable and I will love you forever :-)


    Thursday, January 1, 2015 11:18 PM

Answers

  • Hi

    This post may assist you.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/9618cd1f-9d8b-4b92-9641-0f6e0b732383/global-variables-how-do-i-add-lightswitch-html-march-2014-release?forum=lightswitch 

    Regards, Mark.


    Mark

    • Marked as answer by Ray de Dufus Saturday, January 3, 2015 5:56 AM
    Friday, January 2, 2015 7:25 AM

All replies

  • Hi

    This post may assist you.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/9618cd1f-9d8b-4b92-9641-0f6e0b732383/global-variables-how-do-i-add-lightswitch-html-march-2014-release?forum=lightswitch 

    Regards, Mark.


    Mark

    • Marked as answer by Ray de Dufus Saturday, January 3, 2015 5:56 AM
    Friday, January 2, 2015 7:25 AM
  • Thanks Mark

    That gave me some hints.  What I've done is set up an entity "Choice" which only has one item with links to other entities Preferred team, Venues etc.  I'm also using this for weightings (eg the value of home ground advantage etc)

    Then I filter games (and whatever else) as follows:

    Private Sub Games_Filter(ByRef filter As System.Linq.Expressions.Expression(Of System.Func(Of Game, Boolean)))
                ' filter = Function(e) e.IntegerProperty = 0
                Dim ch As Choice
                Dim nm As String
    
                ch = DataWorkspace.ApplicationData.Choices_SingleOrDefault(1)
                nm = ch.PreferredTeam.Name
    
                If nm <> "1-NoTeam" Then
                    filter = Function(Fi) Fi.AwayTeam.Name = nm Or Fi.HomeTeam.Name = nm
                End If
    
    
    
            End Sub
    Obviously I can use the values of weightings in the same way in the business rules. Cheers
    Saturday, January 3, 2015 5:56 AM
  • Hi Ray

    Glad to hear the info was useful.

    Cheers, Mark.


    Mark

    Saturday, January 3, 2015 7:28 AM