Labels and listViews are not populating with correct TinyDB list info

Thanks for your updated share.

I could see the above coming in handy for updating entries in my app. Thanks.

Regarding your suggestions for my code. Thank you.

It all works as planned with the exception of the last bit of code:

...the part where goals are supposed to be displayed in the ListView based on the role chosen. No roles whatsoever show up in that ListView, depsite there being goals in the DB under different roles.

The rest works great though. Hopefully, I will have some time tonight to analyze why your code works.

That last part can be debugged using the Companion, applying Do It to each value working from right to left.

when Be_BackButton5_BackToMain Click do 
    open another screen screen screenname (BE_MENU) 

initialize global roleTable to
    create empty list

initialize global selectedRoleName to ""

initialize global myGoalsList to 
    create empty list

to GetRolesFromTinyFB do 
    initialize local roleList to 
	call TinyDB.GetValue
		tag "roles"
		valueIfTagNotThere
			create empty list
	in set global roleTable to 
		get roleList

to roleNames result
    make new list from 
	call TinyDB.GetValue
		tag "roles"
		valueIfTagNotThere create empty list
    mapping each role to 
        select list item 
		list get role
		index 1

to goalNames goalTable result
    make a new list from get goalTable
    mapping each goal to 
        select list item list get goal
            index 1

when BE_Role_Report Initialize do 
    set global roleTable to 
	call TinyDB.GetValue
	    tag "roles"
	    valueIfTagNotThere create empty list
    set ListPicker1_RoleReport.Elements to 
	call roleNames
    set global myGoalsList to 
	call TinyDB.GetValue
	    tag "myGoals"
   	    valueIfTagNotThere create empty list

to GoalsWithRole roleName result
    make new filtered list from 
	call TinyDB1. GetValue
	    tag "myGoals"
	    valueIfTagNotThere create empty list
    keeping each goal passing 
    test =
	select list item 
	    list get goal
	    index 
	get roleName

to role roleName result
    reduce 
	list 
	    call TinyDB.GetValue
	        tag "roles"
		valueIfTagNotThere create empty list
	starting with initialAnswer create empty list
    by combining currentRole and answersSoFar
        if 
	    =
		select item 
		    list get currentRole
		    index 1
        then get currentRole
	else get answersSoFar

when ListPicker1_RoleReport.AfterPicking do
    set global selectedRoleName to ListPicker1_RoleReport.Selection 
    set Label_RoleSelected.Text to select list item
	list call role
	    roleName ListPicker1_RoleReport.Selection
	index 1
    set Label_RoleReportVision.Text to select list item
	list call role
	    roleName ListPicker1_RoleReport.Selection
	index 2
    set Label_RoleReportDOH.Text to select list item
	list call role
	    roleName ListPicker1_RoleReport.Selection
	index 3
    set Label_RoleReport_Goals.Text to
	call goalNames
	    call GoalsWithRole
		roleName ListPicker1_RoleReport.Selection

(editted)
*this forum isn't preserving my identations.

For a section of code, use ``` at the start of a line, top and bottom.

  like this

Thanks!

Using the DoIt feature on AI companion for the first time.

Here are the results I am getting:

image

The problem seems to be with the "call goalNames" block.

The values are not being passed from the block where the goals are compiled into a reduced table to were the goals are being set to the ListView_RoleReport_Goals. I'm not sure why.

Working on it more now....(half an hour later.)

Ok, I think I got it.

when I DoItNow, on the "to GoalsWithRole roleName result" block, it gives me these outputs:

Do It Result: [["Run the Boston Marathon", "(Runner Run a marathon Run everyday)", "(this fall 2024-09-22 2024-12-21)", true]
["Do a gallery show", "(Artist make great art paint every day)", "(this summer 2024-06-22 2024-09-21)", true]

and so on...

I think what is happening is that it is looking at the second index of the myGoals table record, is looking for "runner" and instead of finding "runner", it is finding the entire concatenated name of the role, the "list of lists" as the entry is created in Screen 5; it is finding "Runner Run a marathon Run everyday" which is not exactly the same so it is turning up a false negative.

What do you think? Thanks in advance for your help.

This does indeed sound like a case of a mismatch between what one table uses as a foreign key and what resides in another table as a primary key.

Having CSV dumps of all related tables to inspect would make this clearer.

Having CSV dumps of all related tables to inspect would make this clearer.

This, I think is the "dump" of what is stored in tinyDB for the relevant screens:
Do It Result: [["Run the Boston Marathon", "(Runner Run a marathon Run everyday)", "(this fall 2024-09-22 2024-12-21)", true], ["Do a gallery show", "(Artist make great art paint every day)", "(this summer 2024-06-22 2024-09-21)", true], ["test", "(Runner Run a marathon Run everyday)", "(this fall 2024-09-22 2024-12-21)", true], ["tour the Louvre", "(Artist make great art paint every day)", "(this fall 2024-09-22 2024-12-21)", false], ["run an ultrathin someday ", "(Runner Run a marathon Run everyday)", "(this fall 2024-09-22 2024-12-21)", true]]


Okay, I am working on Screen 5, where goals are saved along with their corresponding goals. At current, the block where a goal is saved (upon clicking the "add goal" button) looks like this:

image

The problems seems to be on this screen. I need to find a way to have the goal save the role just by the role name, not the entire concatenated record.

Thanks as always!

Just in case the problem was way back in Screen 3: Define a Role, which is the screen where roles are originally created, I did a DoItNow for when the button is clicked to create the role.

Here is the output:

Do It Result: [["Artist", "make great art", "paint every day"], ["Runner", "Run a marathon", "Run everyday"]]

As you can see, here the "records" of the "table" are not yet concatenated; as you'd you hope, they are still individual fields of the records. So there problem is not here I think.

Here's your problem.
4aa1190b78594cfc50d677be2cdd0276fbb0902b
Only load keys into a ListView Elements, not entire records.

It's not a showcase, it's a vending machine for keys.

I've been trying to fix this for two sessions now (I can only work on this on weekends for now).

Here is what I've been trying to do for Screen 05: Be_Goal and Big Rock Define.

Here's the top of my block where my variables are initialized and such:

image

Here is the screen initialization block:

image

This piece is new, in that we are trying to pull just the role name for the listpicker:

image

It is working: only the role's name appears in the role ListPicker.

Here are the blocks for when the "add role" gets clicked.

image

It know longer
a) successfully adds new roles to the goals ListView
b) successfully adds the old roles to goals ListView

However, I do believe the new goals are being add to the tinyDB, because I created a debugging notification:

image

...and it does show the values for the new goal added. Indeed, it even (correctly) shows the new goal with just the role name attached, not other (unwanted) fields.

Any advice any of you could provide to provide to get this working would be appreciated. I feel so close!

no longer?

yes, it no longer. Sorry.

08c46e559fa6e38d6d3498de01213bbcac4c6da1
How do I know that the global variable is fresh, and reflects the current TinyDB contents.

I like to get my data from TinyDB immediately before I add to it, then put it back in TinyDB, to maintain only one version of the truth.

I've also created a notification debugger that tells us what exactly the ListView is trying to display:

image

This is the message it displays:

image

This tells me that

Insight 1: All of these are "old goals" in the sense that they were added to TinyDB a few weeks ago before we made some more radical changes to the code. None of these are "new goals" from the last 10 or so times I have attempted to add a goal since we started with this newer code.

Insight 2: The ListView is "pulling" from the Database just goal names, probably because of this code:

list ListView_myGoals.Elements
item select list item
list goal
index 1

Ideally, the ListViewer should be showing 1) goal name 2) name of the role it is associated with, 3) the name of the timeframe it is associated with 3) and whether or not is a big rock.

To be sure, in the DB, the goal should NOT be saved as a concatenated list of these values. Each value should be separate because we need to pull that apart elsewhere in the code. But the listViewer should be displaying the 4 fields.

  • Why is it that new goals are being added to the DB (as proven by our first test with the first debug notifier) but this is not being pulled by the ListView.

  • The ListPicker is indeed pulling from the database but...is it pulling from the right place, the right list? Is myGoalsList the right list to pull from? It should be because that is the variable/list that we are populating upon .click.

So should I have my "add items to list" block lower in the when button.click block? Is it that simple?

That's a problem with ListViews.
They don't have events like List Pickers where you can load their Elements from TinyDB before displaying their Elements.

If you love your ListViews, you must initiate an update regimen for them, and follow it faithfully in your coding of updates to their underlying data.

Typically, this is done by writing update (setter/getter) procedures with sole responsibility for those updates and the refreshing of associated display elements, and putting the setter/getter procedures in sole charge of updating that data. (No more direct global table or TinyDB updates.)

I'm digesting your reply. I hope to respond in a little while. Thank you.

Here are some questions:

i) ABG: "They don't have events like List Pickers where you can load their Elements from TinyDB before displaying their Elements."

  • does this mean that we can't program the ListPicker to set its elements within a when.click-do block? In other words, is this block:
    image

...is ineffective?

  • ABG: "If you love your ListViews, you must initiate an update regimen for them, and follow it faithfully in your coding of updates to their underlying data."

So, I can expect for the DB to be appropriately updated, but there to sometimes be a "lag" with how the ListView updates?

  • Is this issue a typical thing in programming? I am using App Inventor to learn algorithms to become a better programmer in general. Can I expect to come across this program elsewhere?

  • ABG: "you must initiate an update regimen for them". How does one do this? "Typically, this is done by writing update (setter/getter) procedures with sole responsibility for those updates and the refreshing of associated display elements, and putting the setter/getter procedures in sole charge of updating that data. (No more direct global table or TinyDB updates.)"

Hmmm, this explanation is "above my current paygrade". But I gather from this that we can't solve our current problem by using a global table. Perhaps some local variable?

Here's a sample test app from another current user's thread, adapted to your question.
Sample run


MultiCheck_Play (2).aia (4.4 KB)

The List Picker's Elements are filtered just In Time before its pop up happens.

The List View's elements are updated within the ListView's Selected event and on initial screen load.

They both had to be programmed, nothing is tied to any database for a free update like in some other introductory all-in-one environments like MS Access.