• Jared
    April 16, 2016 at 12:10 pm #1607

    This should be pretty simple but running into issues and thought I would ask the experts ;-). I need to have some output text showing the number of rows in a table via a formula (so it updates automatically when the table rows are added or removed). I have tried “COUNT(${myTable})” as well as trying to count the specific column like this: “COUNT(${myTable/myColumn}”. It is very possible I am not using the “COUNT” correctly but let me know what I should use…

    Rex Townsend
    April 16, 2016 at 1:10 pm #1608


    One way to get the number of rows in a table is by referencing the table using the getRecords() function. I put my Output Text above the table (so it’s loaded when the table loads) and within the Table configuration options, in the “On Rows Loaded” and “On Deleting Record” of the Events section, I wrote:


    • In this example, “Output_Text1” is the control ID of your SPARK output text control
    • Also, “me” is used to reference the table and is OK to use since the context in which we’re calling “getRecords()” is inside the Table control itself

    Furthermore, if you would like to show the record count below the table, but are running in to issues because the output text is rendered on the coach after the table tries to update the count, then you need another place to store that data. Here is how I would do it:

    1. Drag a Data control on to the pallet, above the Table. Bind a new Private Integer to the Data control
    2. In the Table’s Event’s configuration options, put this code in whichever events you deem necessary for your use case:
      1. ${Data1}.setData(me.getRecords().length)
    3. Now, in the Data control’s Change event handler, add this:
      1. ${Output_Text1}.setText(me.getData())

    Hope this helps. Let us know if you have any follow-up questions.

    April 16, 2016 at 1:26 pm #1609

    Thanks, Rex! This is working now but I need to set the field at each of the relevant events (on load, delete and add). Also, a small clarification that the On Deleting Record event should actually be:

    ${Output_Text1}.setText(me.getRecords().length – 1)

    since the record length property is the number of records before the record is removed.

    Is there a way to do this with the formula in the output text so that I have 1 place for the code?

    SPARK Support
    April 18, 2016 at 6:02 am #1613


    Are you saying that ${<TableCtlId>}.getRecordCount() is not returning the proper value?  When I put this in the formula of an Output Text control it works for me.  Maybe I am missing something?



    Rex Townsend
    April 18, 2016 at 2:03 pm #1624


    A more elegant solution than the one I initially provided would be to use a formula (as your were originally trying to do) within a Formula configuration option of an Output Text. This will also update right when you delete a row in a table. In this example, the control I’m counting is Integer3.

    • COUNT(${Table1/Integer3*})

    So basically, your initial formula with myTable myColumn is just missing an asterisk!

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

Start typing and press Enter to search