none
HTML Client - Dynamically count records in a collection on browse screen RRS feed

  • Question

  • Hi all.  I'm new here and have searched for the answers to my questions to no avail, so apologies if I missed the answer elsewhere!

    I'm trying to build a LightSwitch HTML Client app and have hit a number of stumbling blocks.  I'm struggling to understand the Javascript side of things, even after following a number of tutorials and blog posts.

    I have a couple of questions, all related within my application, so I'll ask them all here.  Apologies again if this is bad form!

    So, the first question I have is as follows.

    I have a Browse screen with parameters to retrieve items from a database and display them in a list on the screen.  That all works fine.  Is it possible to display a count of the number of the items in the list and have it update dynamically as the different parameter options are changed?

    Related to that, is it possible to have a button on the screen to open an AddEdit screen (for adding new records only, not editing existing ones) that is only enabled if the list is not empty?

    Finally, once the user has searched using the parameters, if they don't find the record they are looking for in the list, they create a new one.  Is it possible to pass the values entered in the search parameters through to the AddEdit screen to automatically populate the data entry fields with those values?

    If so, how?  I would appreciate being pointed in the right direction!  :)

    A bit of background, the application is to add qualification aims records to a database.  The database will already contain many qual aims and we want to try to reduce the number of duplicate entries, so the user first searches the database for an existing qual aim.  If one is found, they don't do anything else.  If there isn't one though, they create it, but can only create a record using the criteria they have used to search (so that they don't search for one thing and then try to enter a completely unrelated record).  The qual aim title field still be editable on the AddEdit screen as the parameter value used to search will not be the full title.

    Very much appreciate any responses.  Thanks.

    Friday, April 19, 2013 12:03 PM

Answers

  • Hi,

    Is it possible to display a count of the number of the items in the list and have it update dynamically as the different parameter options are changed?

    Yes, the Visual Collection exposes state change events that you can leverage. I would add a Screen Local Property of type Integer, display it on the screen, then write code to listen to the Visual Collection and update its value. For example:

    myapp.BrowseCustomersByCountry.created = function (screen) {
        screen.Customers.addChangeListener("state", function () {
            if (screen.Customers.state === msls.VisualCollection.State.idle) {
                screen.CustomersCount = screen.Customers.data.length;
            }
        });
    };

    is it possible to have a button on the screen to open an AddEdit screen (for adding new records only, not editing existing ones) that isonly enabled if the list is not empty?

    Yes, you can write a custom method and implement its canExecute function based on the Visual Collection's state property. The nice thing is that doing this will set up dependency tracking so changes are automatically handled. For example

    myapp.BrowseCustomersByCountry.MyCustomAddCustomer_canExecute = function (screen) {
        return screen.Customers.state === msls.VisualCollection.State.idle &&
            screen.Customers.data.length > 0;
    };

    Is it possible to pass the values entered in the search parameters through to the AddEdit screen to automatically populate the data entry fields with those values?

    Yes, in your custom method above, invoke show screen method with your custom beforeShown callback. In that callback you can create a new entity and populate the fields you like. For example

    myapp.BrowseCustomersByCountry.MyCustomAddCustomer_execute = function (screen) {
        return myapp.showAddEditCustomer(null, {
            beforeShown: function (addEditScreen) {
                var c = new myapp.Customer;
                c.Country = screen.Country;
                addEditScreen.Customer = c;
            }
        });
    };

    Here's a sample project if you're interested.

    Best regards,
    Huy Nguyen

    Friday, April 19, 2013 7:35 PM

All replies

  • I posted this somewhere in the past based on info from Paul Van Bladel:

            partial void bCountResults_Execute()
            {
                int tSavePageNumber = this.WOWorkOrdersSQ.Details.PageNumber;
                int numberOfPages = this.WOWorkOrdersSQ.Details.PageCount;
                int tPageSize = this.WOWorkOrdersSQ.Details.PageSize;   // Number of rows in a collection
                int tLastPageRecCount = 0;
                vWORecordCount = 0;
    
                if (numberOfPages > 0)
                {
                    this.WOWorkOrdersSQ.Details.PageNumber = numberOfPages;
                    tLastPageRecCount = WOWorkOrdersSQ.Count;
    
                    vWORecordCount = tPageSize * (numberOfPages - 1) + tLastPageRecCount;
                    this.WOWorkOrdersSQ.Details.PageNumber = tSavePageNumber;
                }
    
            }
    vWORecordCount is a local screen integer.


    Garth Henderson - Vanguard Business Technology

    Friday, April 19, 2013 4:54 PM
  • Other questions:

    • Related to that, is it possible to have a button on the screen to open an AddEdit screen (for adding new records only, not editing existing ones) that is only enabled if the list is not empty?

    Sure, you can disable the button based on row count.

    • Finally, once the user has searched using the parameters, if they don't find the record they are looking for in the list, they create a new one.  Is it possible to pass the values entered in the search parameters through to the AddEdit screen to automatically populate the data entry fields with those values?

    Yes.  However, keep in mind that you could also use Modal windows, Screen sections, and tabs to add/edit new records.  You can make visible or readonly any screen section (row or column layout).

    Buy and read:  Pro Visual Studio LightSwitch 2011

    Tim has an updated version for 2012 - but it isn't available in Kindle yet.   Kindle runs on your PC.


    Garth Henderson - Vanguard Business Technology


    Friday, April 19, 2013 5:03 PM
  • Hi,

    Is it possible to display a count of the number of the items in the list and have it update dynamically as the different parameter options are changed?

    Yes, the Visual Collection exposes state change events that you can leverage. I would add a Screen Local Property of type Integer, display it on the screen, then write code to listen to the Visual Collection and update its value. For example:

    myapp.BrowseCustomersByCountry.created = function (screen) {
        screen.Customers.addChangeListener("state", function () {
            if (screen.Customers.state === msls.VisualCollection.State.idle) {
                screen.CustomersCount = screen.Customers.data.length;
            }
        });
    };

    is it possible to have a button on the screen to open an AddEdit screen (for adding new records only, not editing existing ones) that isonly enabled if the list is not empty?

    Yes, you can write a custom method and implement its canExecute function based on the Visual Collection's state property. The nice thing is that doing this will set up dependency tracking so changes are automatically handled. For example

    myapp.BrowseCustomersByCountry.MyCustomAddCustomer_canExecute = function (screen) {
        return screen.Customers.state === msls.VisualCollection.State.idle &&
            screen.Customers.data.length > 0;
    };

    Is it possible to pass the values entered in the search parameters through to the AddEdit screen to automatically populate the data entry fields with those values?

    Yes, in your custom method above, invoke show screen method with your custom beforeShown callback. In that callback you can create a new entity and populate the fields you like. For example

    myapp.BrowseCustomersByCountry.MyCustomAddCustomer_execute = function (screen) {
        return myapp.showAddEditCustomer(null, {
            beforeShown: function (addEditScreen) {
                var c = new myapp.Customer;
                c.Country = screen.Country;
                addEditScreen.Customer = c;
            }
        });
    };

    Here's a sample project if you're interested.

    Best regards,
    Huy Nguyen

    Friday, April 19, 2013 7:35 PM
  • Sorry guys, I missed that this was for an HTML client.

    Thanks for your reply Huy!

    Huy, is there documentation on how we can access all of the Visual Collection properties from the backend web service via HTML?


    Garth Henderson - Vanguard Business Technology

    Friday, April 19, 2013 7:51 PM
  • No worries, Garth.  I appreciate you taking the time to respond.

    Thanks Huy.  I may not get a chance to try any of this out until Monday but that looks like a pretty comprehensive answer!

    Friday, April 19, 2013 8:03 PM
  • Using Huy's example app:

    1) How do we use Paging with the HTML Client (HC)?

    I changed the # of items per page to 5 - but the screen still shows all records?

    Also, where is the documentation to use LINQ to get required information  from the Visual Collections in the HC Screen methods?

    http://msdn.microsoft.com/en-us/library/vstudio/jj674623.aspx


    Garth Henderson - Vanguard Business Technology


    Friday, April 19, 2013 8:15 PM
  • Thankfully, with the magic of remote connection, I've managed to test Huy's response.  All worked absolutely perfectly!  Thank you very much!

    Next thing I have to do is use one of the parameters to filter a list of codes in the database to find the next number in a sequence in the process of passing the code through to create a new entity.  I have an idea of how to approach that, but I may be back with more questions next week!  :)

    Friday, April 19, 2013 8:49 PM
  • Hi Garth,

    In HTML Client, the List View does 'continuous loading' (following the model of popular web sites). The List View will try to load items until it fills up the page, then as you scroll down, it will try to load more items. So the page size is now only used to control the number of items that are loaded with each queries, but the list will send as many queries as it needs to fill the page. Also there's no jump to page number like Silverlight Client any more.

    Unfortunately there's no LINQ in JavaScript yet. So the Visual Collection simply exposes a property called data that will give you an array representing the data currently loaded. LightSwitch does has a utility method that can get you closer to LINQ. There's no documentation for it, but hopefully Intellisene will work. Here's a sample snippet

        msls.iterate(screen.Customers.data)
            .where(function (c) {
                return c.Country === "France";
            })
            .sum(function (c) {
                return c.EmployeeCount;
            });

    Best regards,
    Huy Nguyen

    Saturday, April 20, 2013 12:59 AM
  • What about http://linqjs.codeplex.com/  or http://jscriptlinq.codeplex.com/ ?

    Are we able to get access to all public methods created in the LS app's web service?

    The msls.iterate() is very helpful.  This goes a long way.   Your explanation about the how a List View goes through all pages is very helpful.

    hmmm . . . do we have access to all PreprocessQuery Parms in a Screen collection?


    Garth Henderson - Vanguard Business Technology

    Saturday, April 20, 2013 1:33 AM
  • Hi Garth,

    What about http://linqjs.codeplex.com/  orhttp://jscriptlinq.codeplex.com/ ?

    I have not tried those out yet. Unless they have conflicts with any libraries used by HTML Client, I don't think there will be a problems using them in an HTML Client project. Sorry, I would clarify that there's no LINQ in LightSwitch JavaScript Runtime yet :) And it'd probably never will since there are already libraries out there.

    Are we able to get access to all public methods created in the LS app's web service?

    You have full access to entity sets and custom queries created on the server's data sources, just as Silverlight Client. screen.details.dataWorkspace.DataServiceName should exposes all the entity sets and custom queries. You can try building up server queries, and open a file named data.js under Client\GeneratedResources folder and see how they're defined.

    do we have access to all PreprocessQuery Parms in a Screen collection?

    You can define custom query on Screen's Collection Property, just as Desktop Client. You can define parameters to them, bind those parameters to Screen's Local Properties. Like in my sample above.

    Those parameters should be passed back to the Server, so you should be able to access them in PreProcess Query on server side.

    Best regards,
    Huy Nguyen

    Saturday, April 20, 2013 2:29 AM
  • Thanks, Huy!

    I'm working through some ideas based on your information.   I'll open separate threads to follow through.


    Garth Henderson - Vanguard Business Technology

    Saturday, April 20, 2013 6:14 PM
  • Hi 
    I download the project VisualCollectionExample, but i note one problem. 
    In the screen 'BrowseCustomerByCountry.js', it count the item in the list use Customers.data.length. But if I add the Custom customer, using the button 'MyCustomAddCustomer', 
    the count label dosen't refresh the value and not increase. 

    Don't exist the manner for do this? 

    Thanks 

    Ale
    Tuesday, July 16, 2013 2:29 PM
  • Hi,

    If you want to also update the count on adding / removing items from the Visual Collection, you need to listen to the collecitonchange event instead.

    myapp.BrowseCustomersByCountry.created = function (screen) {
        screen.Customers.addEventListener("collectionchange", function () {
            if (screen.Customers.state === msls.VisualCollection.State.idle) {
                screen.CustomersCount = screen.Customers.data.length;
            }
        });
    };

    Please be aware that the Visual Collection cannot filter data on the client. So if you add a Customer that is supposed to be from France, but change your mind and put in USA instead, that Customer will still show up on the Client and the count will still be updated. That behavior is by design.

    Best regards,
    Huy

    Tuesday, July 16, 2013 3:05 PM
  • Hi,

    your answer was perfect! Thanks.

    But I have one other issue.

    When I count the items (for example of 1000 records) in the list, in LightSwitch HTML,  the program upload only few items in the DataBase and when I scroll down the scrollbar of right in the browser, the application upload other items, etc...

    It doesn't upload all items.

    Why? 

    Doesn't exists the manner for do this?



    Thanks, best regards

    • Proposed as answer by Arenaut Wednesday, July 17, 2013 9:04 AM
    Wednesday, July 17, 2013 8:24 AM
  • Hi,

    Just to be clear, the HTML Client is not uploading items, it is loading items from a database. Paging over a large data set is a common concept to reduce the amount of data loaded through the while. It's actually easier to load all records, but what happens if your table has 1,000,000 records and your user is accessing it through a mobile device with data charge? Your user will have to wait quite a bit and pay quite a bit of money. There are two common paging methods for web pages:

    • Using page numbers, like this forums.
    • Keep loading more items when the page is scrolled down, like common social feeds. The HTML Client picks this behavior.

    If you want to count the number of records on your client, the method above can be used.

    If you want to count the number of records on the server, it will be much faster and less cost to use includeTotalCount() query. For example if I want to know how many Customer records are on the server, I will add a screen local property named TotalCount, of type Integer. And in my screen created I would write

    myapp.BrowseCustomers.created = function (screen) {
        myapp.activeDataWorkspace.ApplicationData
            .Customers
            .top(1)
            .includeTotalCount()
            .execute()
            .then(function (result) {
                screen.TotalCount = result.totalCount;
            }, function (error) {
                screen.TotalCount = -1;
            });
    };

    Our main target here is to get the total count, so we just issue a query asking for the first record (if the database has any), asking the database to include total count, then when the query is executed, we just use the returned total count.

    A couple of notes:

    • To dynamically update this total count, you will need to add even listeners and execute the query again. The Visual Collection will not help because the Visual Collection is only concerned about data on the Client, not the Server.
    • Items that are added and not saved on Client will obviously not be counted (as opposed to the Visual Collection).
    • Some data sources (like OData) may not support include total count, so your query may fail.

    Another way is to turn off paging, then the Visual Collection will load all item. Be careful when using this due to the scenario on top.

    Best regards,
    Huy

    Wednesday, July 17, 2013 2:59 PM
  • The answer is perfect!!

    Great article, it's exact.

    Thanks, best regards



    Ale

    Wednesday, July 17, 2013 3:28 PM
  • Huy,

           I cannot download the project, in skydrive, I see the download menu button, but when I click it, nothing happens (whether I'm logged in or not).

    Scott

    Monday, January 20, 2014 8:07 PM
  • Hi,

    Is it possible to display a count of the number of the items in the list and have it update dynamically as the different parameter options are changed?

    Yes, the Visual Collection exposes state change events that you can leverage. I would add a Screen Local Property of type Integer, display it on the screen, then write code to listen to the Visual Collection and update its value. For example:

    myapp.BrowseCustomersByCountry.created = function (screen) {
        screen.Customers.addChangeListener("state", function () {
            if (screen.Customers.state === msls.VisualCollection.State.idle) {
                screen.CustomersCount = screen.Customers.data.length;
            }
        });
    };

    is it possible to have a button on the screen to open an AddEdit screen (for adding new records only, not editing existing ones) that isonly enabled if the list is not empty?

    Yes, you can write a custom method and implement its canExecute function based on the Visual Collection's state property. The nice thing is that doing this will set up dependency tracking so changes are automatically handled. For example

    myapp.BrowseCustomersByCountry.MyCustomAddCustomer_canExecute = function (screen) {
        return screen.Customers.state === msls.VisualCollection.State.idle &&
            screen.Customers.data.length > 0;
    };

    Is it possible to pass the values entered in the search parameters through to the AddEdit screen to automatically populate the data entry fields with those values?

    Yes, in your custom method above, invoke show screen method with your custom beforeShown callback. In that callback you can create a new entity and populate the fields you like. For example

    myapp.BrowseCustomersByCountry.MyCustomAddCustomer_execute = function (screen) {
        return myapp.showAddEditCustomer(null, {
            beforeShown: function (addEditScreen) {
                var c = new myapp.Customer;
                c.Country = screen.Country;
                addEditScreen.Customer = c;
            }
        });
    };

    Here's a sample project if you're interested.

    Best regards,
    Huy Nguyen

    Huy,

    I am trying to do this exact thing - display the number of items in a 'collection' on the screen.

    I am using cascading Details Pickers on a BrowseScreen. I choose my Building > then choose the Classroom in that building > I then get a list of Devices in that classroom. I am trying to display the total number of Devices in that list on the screen.  I am confused about the first part - I created a Local Property called 'ListCount', type integer, and placed it on the BrowseScreen. 

    I then chose Write Code > Created on the BrowseScreen. I am using this code...

    myapp.BrowseDevices.created = function (screen) {
        // Write code here.
        screen.Devices.addChangeListener("ListCount", function () {
            if (screen.Devices.ListCount === msls.VisualCollection.State.Idle) {
                screen.DevicesCount = screen.Devices.data.length;
            }
        });
    };

    'ListCount' is the name of the Local Property I created for the first part of your tutorial. Where is this code going wrong? There is no build error, but it is also not working.

    Thank you so much!!

    Friday, March 4, 2016 3:49 PM
  • You need to listen to a change of the 'state' property of the devices collection and if the state is idle (meaning the data is done loading) then set the ListCount local property.

     Try this:

    myapp.BrowseDevices.created = function (screen) {
        // Write code here.
        screen.Devices.addChangeListener("state", function () {
            if (screen.Devices.state === msls.VisualCollection.State.Idle) {
                screen.ListCount = screen.Devices.data.length;
            }
        });
    };

    HTH,

    Josh

    Friday, March 4, 2016 4:10 PM
  • Hello Josh,

    Thanks a lot!! I actually got this working (at least, doing what I wanted to achieve) by using this walk-through from Micheal and Huy.

    The working code example in particular is here:

    We use the following code:
    
     
    
    myapp.BrowseCustomers.Customer_postRender = function (element, contentItem) {
        // Set up a databind on screen.Customers.count
        contentItem.dataBind("screen.Customers.count", function (newValue) {
            // Update the total records display
            DisplayCustomerCount(contentItem.screen);
        });
    };
    // Utility
    function DisplayCustomerCount(screen) {
        // If there is a Customer collection
        // display the current count
        if (screen.Customers != undefined && screen.Customers != null) {
            var strDisplayText = "Loaded Customers: " + screen.Customers.count;
            screen.details.displayName = strDisplayText;
        }

    Thanks again!

    Friday, March 4, 2016 4:41 PM
  • That works too however, addChangeListener on 'state' is better if you're doing aggregates because sometimes the .count property doesn't change as expected so your dataBind code might not fire as expected.

    For example, say you're doing inventory, you have a Device.QtyInStock property and you want to display the total quantity of all Devices. User executes a filter and 3 devices are retuned, your .count is 3 and the total quantity in stock is calculated correctly.  So far so good.  Now the user changes the filter, 3 different devices are returned, the count remains 3 and your quanity calc doesn't fire.

    Running your calc everytime the collection state becomes idle is better to ensure the code fires everytime a collection load completes.

    HTH,

    Josh

    Friday, March 4, 2016 5:08 PM
  • That works too however, addChangeListener on 'state' is better if you're doing aggregates because sometimes the .count property doesn't change as expected so your dataBind code might not fire as expected.

    For example, say you're doing inventory, you have a Device.QtyInStock property and you want to display the total quantity of all Devices. User executes a filter and 3 devices are retuned, your .count is 3 and the total quantity in stock is calculated correctly.  So far so good.  Now the user changes the filter, 3 different devices are returned, the count remains 3 and your quanity calc doesn't fire.

    Running your calc everytime the collection state becomes idle is better to ensure the code fires everytime a collection load completes.

    HTH,

    Josh

    Excellent. I will try to get this going. Will this still be expected to work if I am creating a list on a Tab off of a Browse Screen?

    Here is what the screen looks like...

    The Tab and the Local Property of type Integer are circled in red. I am trying to show the number of items in the list that is made when a Building and then DeviceType are chosen in the query below the ListCount Local Property.

    Here is the code I am using, but it looks more like it would be counting the Devices from the BrowseScreen?...

    myapp.BrowseDevices.created = function (screen) {
        // Write code here.
        screen.Devices.addChangeListener("state", function () {
            if (screen.Devices.state === msls.VisualCollection.State.Idle) {
                screen.ListCount = screen.Devices.data.length;
            }
        });
    };

    I get no breaks when I run this, but I must be doing something wrong.

    Wednesday, March 9, 2016 9:18 PM
  • Here is the code I am using, but it looks more like it would be counting the Devices from the BrowseScreen?...

    myapp.BrowseDevices.created = function (screen) {
        // Write code here.
        screen.Devices.addChangeListener("state", function () {
            if (screen.Devices.state === msls.VisualCollection.State.Idle) {
                screen.ListCount = screen.Devices.data.length;
            }
        });
    };

    I get no breaks when I run this, but I must be doing something wrong.

    I think it should be something like:

    myapp.BrowseDevices.created = function (screen) {
        // Write code here.
        screen.DeviceTypeByBuildings.addChangeListener("state", function () {
            if (screen.Devices.state === msls.VisualCollection.State.Idle) {
                screen.ListCount = screen.DeviceTypeByBuildings.data.length;
            }
        });
    };

    If you put a breakpoint on line beginning screen.ListCount = then you can inspect to confirm that the collection on that tab is indeed called 'DeviceTypesByBuildings'.  LS will pluralize the collection name, but sometimes it's not what we might expect.

    HTH,

    Josh


    • Edited by joshbooker Wednesday, March 9, 2016 9:49 PM
    Wednesday, March 9, 2016 9:48 PM
  • Thank you, Josh,

    I adjusted the code to reflect what you have suggested. Again, no breaks, but no count.

    Is it something simple to do with the Local Property? It is type Integer but on the screen is set to Text. I am not sure I saw what it should be in Huy's tutorial. Anyway, just curious if your code is working but it isn't displaying for some other reason.

    As far as using the breakpoint, I set one on the line screen.ListCount = , and then started debugging. I went through the motions of generating a list and - though I am sure to be wrong about this - the behavior did not change. The list was generated, but no count appeared.

    Wednesday, March 9, 2016 10:05 PM
  • Try this:

    myapp.BrowseDevices.created = function (screen) { // put breakpoint on next line //alert(screen.DeviceTypeByBuilding); screen.DeviceTypeByBuilding.addChangeListener("state", function () { if (screen.Devices.state === msls.VisualCollection.State.Idle) { screen.ListCount = screen.DeviceTypeByBuilding.data.length; } }); };

    The issue is we don't know for sure the name of the collection on the second tab.  I guessed it was called 'DeviceTypeByBuildings', but perhaps that's wrong

    If this doesn't work, then remove '//' in front of 'allert' and put a breakpoint on that line then F5. 

    When it breaks on that line press F10, what does the msgbox say?  Then hover on the word 'screen' in the code, expand to inspect the properties of screen object.  Is there anything that resembles 'DeviceTypeByBuilding'?  If so replace 'DeviceTypeByBuilding' in the code above.

    HTH,

    Josh

     
    Wednesday, March 9, 2016 10:39 PM
  • Thank you, Josh!

    I used the code above, put a break point on the line alert(screen.DeviceTypeByBuilding);

    I hope that is the line you meant. The same thing happens when it breaks on the line below as well.

    I then hit F5. Debugging starts. This is what the alert says, and it says it when I hit the button that navigates to BrowseDevices. Other words, when BrowseDevices is created. My tab is on the BrowseDevices screen, and it is called 'Advanced Filtering' as you see above. Anyway, this is the alert message...

    Intellisense does find DeviceTypeByBuilding for use after screen. DeviceTypeByBuilding is the name of the query I made in the query designer and then added to the screen, under the Tab on the BrowseDevices screen. 

    During debugging with that break point, when I hover over screen.ListCount = , it says screen.ListCount undefined. The integer Local Property I added to the screen is called ListCount, for sure.

    Thanks again!


    • Edited by CreedCor Thursday, March 10, 2016 3:48 PM
    Thursday, March 10, 2016 3:47 PM
  • [object Object] is the correct alert that tells us we got the collection property name correct (DeviceTypeByBuilding).  Now remove the alert line and run it.  Does the count work?
    Thursday, March 10, 2016 4:37 PM
  • It does not. I am looking for a value to be displayed under the Display Name of the ListCount property, yes?

    I added ListCount to the screen and this is what it looks like...

    The table below it called DeviceTypeByBuilding is the list I am creating and counting. The list is generated when a Building and DeviceType are both selected in the Details Pickers above.

    This is what it looks like on the screen itself..

    'Number of Devices in your selection:' is the Display Name I gave to ListCount.

    • Edited by CreedCor Thursday, March 10, 2016 5:26 PM
    Thursday, March 10, 2016 5:20 PM
  • Put a breakpoint on this line:

    screen.ListCount = ...

    Now F5 and show that tab - does breakpoint hit? 

    If not, Choose your parameters - now does it hit?

    If so, inspect the objects, does sceen.ListCount exist?  How about screen.DeviceTypeByBuilding.data?

    Thursday, March 10, 2016 5:50 PM
  • The break never hits when the breakpoint is on this line

    screen.ListCount = ...

    On the other two lines above it, it breaks when I navigate to BrowseDevices. Not the tab on the BrowseDevices screen, but the BrowseDevices screen itself.

    With a breakpoint on screen.ListCount =, I can go through the whole app without it breaking.

    ListCount and DeviceTypeByBuilding both exist in the sense that Intellisense does find them and says, '(member variable) Gets or sets the listCount for this screen'.

    Thursday, March 10, 2016 6:50 PM
  • Oops I see the prob. Change screen.Devices.state to screen.DeviceTypeByBuilding.state on line 49.
    Thursday, March 10, 2016 7:23 PM
  • I wish it were that easy! Haha. I know it will be something simple, just not tracking it down yet.

    I have been trying all combinations of screen.Devices/DeviceTypeByBuilding and haven't had it work yet.

    However, the more I look at this, the more it really starts to make sense. The code is saying:

    When BrowseDevices is Created, sit a ChangeListener on the entity DeviceTypeByBuilding. If that property is idle, send the data length of that entity's list to a separate screen entity called ListCount, which is type Integer.

    If only it made that much sense to LS ;).

    The code now has DeviceTypeByBuilding in all lines instead of Devices. Intellisense doesn't like the addChangeListener where it is, if that is any help.

    Thursday, March 10, 2016 8:33 PM
  • Try addEventListener on collectionchange instead:

        screen.DeviceTypeByBuilding.addEventListener("collectionchange", function () {
            if (screen.DeviceTypeByBuilding.state === msls.VisualCollection.State.idle) {
                screen.ListCount = screen.DeviceTypeByBuilding.data.length;
            }
        });

    HTH,

    Josh

    Thursday, March 10, 2016 9:13 PM
  • No dice. I so appreciate all of your efforts...I am trying to make them pay off! Hahah.

    At this point it doesn't seem to care what is on the line screen.ListCount =.

    I can change the property before .data.length to anything I want and it doesn't break. Other words I can use this line...

    screen.ListCount = screen.IntBuildingID.data.length;

    and it doesn't break. It's like it isn't executing that bit.

    Friday, March 11, 2016 6:58 PM