Search code examples
visual-studio-2013visual-studio-lightswitchlightswitch-2013

Pass Value from one screen to another screen filter Parameter


Hi i am developing LightSwitch HTML client using VS 2013

need some ideas for,

I am having one browse screen for eg please refer the below,

BrowseEmployee

enter image description here

when i click on any row, it will lead to another screen (Not to the same entity View screen). In the another screen i am going to show with the lot of details,

ViewResourceAllocation

enter image description here

and in this screen i am pulling from SQL view entity, this will have ID field which is common to the previous screen (BrowseEmployee)

Now my question is,

  1. If i click the ID 1 employee in the 1st screen here i need to show only the Employee ID 1 details alone.

  2. Even i tried to pass the value as parameter to the filters in the second screen, nothing is working out. So it will be convenient if i pass the value as filter parameter to the other screen.

Can anyone please tell me how to sort out this issue ?

thanks!


Solution

  • One important bit of info first, make sure the ViewScreen is actually associated to your Engineers screen, not the ResourceAllocation screen, as there is a foreign key linking them together, then the information can be accessed this way. so BrowseEngineers will go to ViewEngineers

    This is how I do it when there is a relationship between the tables, so on your side bar you should see "Edit Query" next to the ResourceAllocation. table. if its just blue under the Employee table click on it and then it will add this table to the screen, then click on the "Edit Query" button

    In here there are 3 options, I will apply it to your tables from above

    1. Filter - [WHERE] [Employee.EmployeeID] [=] [passEmployeeID]
    2. Sort //not needed in this example
    3. Parmeters = [Parameter] [passEmployeeID] of type [Integer]

    Now when you click "Back to ViewResourceAllocation", under the ResourceAllocation table your parameter you have just created is now present. Then do the following steps

    1. Drag this onto the screen and set its properties to be "Not Visible"
    2. click "Edit postRender Code" and type the following code in:
    myapp.ViewEpmloyees.passEmployeeID_postRender = function (element,   contentItem) {
          contentItem.screen.passEmployeeID=
          contentItem.screen.Employees.EmployeeID;
         };
    

    We have just created a filter for the ResourceAllocation Table, and set is as a parameter, then now we need this to have a value, so we assign it before the screen renders as the Employee's ID you clicked on from the previous BrowseEmployees screen which Lightswitch passes for you.

    Hopefully this will solve the problem you are having.

    NOTE: make sure that you also have the EmployeeID on the screen, and if you don't want the user to see it, make it "Not Visible"