locked
HTML Client - (hopefully) final considerations on refresh() API RRS feed

  • Question

  • Thanks to answers receievd with linked articles :

    http://social.msdn.microsoft.com/Forums/vstudio/en-US/d8d56a9d-7260-44ba-964c-2552881b3ec1/html-client-reload-children-after-logic-tier-calculation?forum=lightswitch#eacb1151-6838-4ed3-b3b6-376b1a02427e

    and other forum resources like this :

    http://social.msdn.microsoft.com/Forums/vstudio/en-US/4896b49c-83c8-49d4-aeb8-940ca53e44d2/propagate-changes-in-database-to-ls-html-client?forum=lightswitch

    put down a Master-Detail-Subdetail test project in VS2013 RC (entities names :'Master','Parent','Child') and I would appreciate a lot your help to understand if there's a better solution, because my js code seems to me a bit complicated and far from elegant, additionally I guess this will help other newbies like me.

    Parent's Children are shown as popup on 'Select Child' click, 'Calculate All' button calls saveChanges and logic tier performs Parents and Children changes/calculation and sums up Master total value.

    This is the (verbose) javascript code with some comments :

    myapp.AddEditMaster.CalculateAll_execute = function (screen) {
        myapp.activeDataWorkspace.ApplicationData.saveChanges().then(function () {
            // Added to get Master Totale Value refreshed on screen
            screen.Parents.selectedItem.details.refresh();
            // refreshes Parents visual collection
            screen.Parents.refresh().then(function () {
                console.log("MAIN REFRESH");
            });
        })
    };
    
    myapp.AddEditMaster.SelectChild_execute = function (screen) {
        if (!screen.Children.isLoaded) {
            // Parent's refresh automatically loads Children
            screen.Parents.selectedItem.details.refresh().then(function () {
                screen.showPopup("ChildrenPopup");
            });
        }
        else {
            // 1. After Calculate/saveChanges Children isLoaded=true but empty
            // 2. At 'SelectChild' Children collection still contains last children shown in popup
            //      (not necessarily Parents.selectedImte children)
            screen.Children.load().then(function () {
                // (Parent not always has Children)
                if (screen.Children.data.length > 0) {
                    for (var i = 0; i < screen.Children.data.length; i++) {
                        screen.Children.data[i].details.refresh();
                    }
                    screen.showPopup("ChildrenPopup");
                }
                else {
                    msls.showMessageBox("No Children for this Parent");
                }
            });
        }
    };

    Any comment/suggestion will be much appreciated, thanks.


    P.S. to clarify my scenario:

    User edits values in 'Parent Value' text box on the visible screen table (this is a Parent entity property/field) and then clicks 'Calculate All' button which calls saveChanges.

    Server side, in 'Parent_Updating' event :

    Parent entity 'Result Value' is calcualted and set, as you can see from the image the sum of all Parents' 'Result Value' is saved on the 'Master' entity (the top entity in the relation chain), then the third table ('Child' that is a child of 'Parent' entity) has some other values changed server side (not shown here for the sake of brevity).

    'Select Child' button that is on every Parent table row executes showPopup to show the collection of Children of the selected Parent entity.

    The problem was that after every change server side I had a lot of trouble in refreshing data on the screen at every level : Master (total value), Parent (result value) and Child popup.

    In addition : every field is calculated from the server but is actually a standard property in each entity, i.e. a regular field in each entity SQL server table.


    Wednesday, October 9, 2013 8:25 AM

All replies

  • Hi,

    could you give more details on what are you trying to test here? what is your scenario? what are you calculating? what exactly do you want to refresh and when?

    Providing these information will help us in giving you more precise answer.

    Wednesday, October 9, 2013 9:34 AM
  • Thank you for your attention and sorry if I wasn't clear...I edit the post to clarify a bit.


    (server calculation logic is not the problem here, nor performances issue due to roundtrips, but just my lack of experience and understanding of javascript object model ,syntax and events)


    Wednesday, October 9, 2013 10:04 AM