locked
refresh a table view on a ParentViewScreen, after pressing save on the ChildScreen RRS feed

  • Question

  • Basically, I have a view screen which contains an additional table of data which are linked by a foreign key, as shown below

    How it Works

    I have added a button associated with the VariationTable to add an additional row, which loads up a child screen. Now when I save this, the new Variation row is displayed on the InvoiceParentScreen, however I cannot edit it until I refresh this table view on the InvoiceViewScreen...

    Is there a way I can refresh this table view in code?

    I have found an example below: 

    myapp.showAddEditProject(null, { beforeShown: function (addEditScreen) { addEditScreen.Project = new myapp.Project(); }, afterClosed: function () { screen.Projects.load(); } });

    However with this code its used from a browse screen to a child, and then back, not my scenario so I have been unable to get it working

    Thankyou for any help


    Cr7

    Friday, August 14, 2015 7:13 AM

Answers

  • A few things to check:

    1) remove the parentheses from the end of the "new myapp.Project();" line.

    2) make sure you are performing an applyChanges or commitChanges before the child screen closes.

    3) Try screen.Projects.refresh() instead of screen.Projects.load() in your afterClosed function.

    4) On your screen that contains the parent table, click on Edit Query for that table and check the Properties for the link that says "Manage Included Data".  Check to see if the Project table is Excluded, and if it is, set it to Included.

    Hope some of this helps,

    R. T. Watkins

    • Proposed as answer by Crezzer777 Tuesday, August 18, 2015 3:03 PM
    • Marked as answer by Crezzer7 Wednesday, August 26, 2015 1:20 PM
    Monday, August 17, 2015 6:56 PM

All replies

  • A few things to check:

    1) remove the parentheses from the end of the "new myapp.Project();" line.

    2) make sure you are performing an applyChanges or commitChanges before the child screen closes.

    3) Try screen.Projects.refresh() instead of screen.Projects.load() in your afterClosed function.

    4) On your screen that contains the parent table, click on Edit Query for that table and check the Properties for the link that says "Manage Included Data".  Check to see if the Project table is Excluded, and if it is, set it to Included.

    Hope some of this helps,

    R. T. Watkins

    • Proposed as answer by Crezzer777 Tuesday, August 18, 2015 3:03 PM
    • Marked as answer by Crezzer7 Wednesday, August 26, 2015 1:20 PM
    Monday, August 17, 2015 6:56 PM
  • i have never seen that 4th option before, that could help me on a lot of the screen :) what exactly is this doing?
    Tuesday, August 18, 2015 3:04 PM
  • It determines whether or not any child data records are loaded when the parent records are loaded. For a quick Browse, you usually don't want the child records, as they may take too long to load if there are a lot of them. It's only when you are Editing or Viewing a single record that you want the child records loaded too.

    However, there are some times when you need to scan through child values for certain business logic, and if you don't have them loaded when the logic executes, they can be reported as "undefined", even though you know they have values. 

    For example, say you're looking at a CustomerOrders table, and it's linked on a CustomerID to your Customers table.  If you just Browse the Orders table in a grid, the Customer will only show up as a CustomerID number.  If you want to see the Customer's full name along with it, you would normally add the linked Customer table to the screen, then drag the FullName field over into your table.  It would show up normally because LightSwitch would "include" that table for you.  But what if you don't do that, and you have some logic when the user selects an Order that tries to see if the Order's Customer's FullName contains, say, the word "Hospital"?  Ordinarily, you'd just do something like:

    if(screen.CustomerOrders.selectedItem.Customer.FullName.search(/[Hh]ospital/g) !== -1) {

        // do something for hospitals here

    }

    It's fine if the Customer record has been loaded when this executes, but if it hasn't, you'll have problems because FullName will be undefined, and obviously an undefined object can't have a .search() method.  Sure, you can get around it by calling CustomerOrders.selectedItem.getCustomer().then(function (orderCustomer) { // do the check on orderCustomer.FullName here});  but that can cause headaches if that table has child records of its own, because you start getting into nested async promise resolution for grandchild records.

    Essentially, by checking Include on that screen, LightSwitch will do the promise-joining for you behind the scenes, and you can even get away with stuff like the parent.child.grandchild.value problem above in many cases (but not all).  However, when things like that come up, it's probably a better idea to re-think your huge Browse screen into several drill-down sub-Browse screens instead.

    Tuesday, August 18, 2015 3:32 PM