Accessing Multi Variable Lists (Arrays)

I’m having trouble accessing data I’ve placed in a list. When the user enters the system I use the Data API to get the records for all the clubs they are associated with and put those records into a list in App Data because I need to refer to it often.

I know the list is getting created correctly. My problem is ACCESSING the information. I can find no examples in the tutorials where multi variable arrays are discussed. (If you have one PLEASE let me know!)

Here’s an example of what I need to do: The User needs to select which club they want to create a new event for. So, I need to create a Select that contains the Club Name and objectID to an event is created for the correct club.

I know I am successfully getting the list from App Data because the correct data is printed:

The problem is how to I then get that information OUT. How do I refer to the Club Name or Club Number or any other element of the list item?

I also tried the above codeless using secClubList.ClubName rather than just ClubName. It didn’t work either.

Thanks!

Hi,
if I understand everything correctly,
then you need to understand which club the user chose in order to create an event based on this data.
If this is so, then you can add the logic in the “On Page Enter” handler that you already have with “Set Options To Select”, a list of clubs will be displayed in your Select, then go to the handlers of the “Select” itself and in the “On Change Event” handler get the value that the user selected.

Regards,
Sergey


Hi Sergey -
I don’t think I explained it correctly. Yes, you understand. I need to create a Select that the user will pick from. My problem is filling the select with data. In your example the purple “Create List With” portion. All the rest is working just fine.

The data I need to read is in a list that contains multiple records that I read from the database upon application entry and store in App Data.

How do I access the data in this list? In my test data it has two items with data fields: ClubName, ClubContactName, objectId, and ownerId. I need to fill the select with the label ClubName and value objectId.

Are you talking about accessing the selected item?

No. I’m talking about accessing a list I have created in App Data. It has two items (see the second picture in my original post). How do I get the ClubName and objectId data fields from the 2 items on that list?

To get data from App Data you retrieve it from App Data. In fact, you are already doing it here:

I am sorry, but I am very confused about what it has to do with the Select component.

I think it’s because my question is either very basic or something that maybe can’t be done. Though why you’d be allowed to create a list that has multiple data elements and then not be able to access the multiple data elements is a bit of a head scratcher.

I have a list with multiple items. Each item has the data elements ClubName, ClubContactName, objectId, and ownerId.

I need to create a Select from this list where the label is ClubName and the value is objectId.

How do I refer to the data elements on the list to create the select? (the purple part of my codeless in my original post)

You are already doing it right here:

Once done, the list has only two items: ClubName and objectId. All other items are not part of the list.

That doesn’t work. Let me try explaining it another way. Here is my list:

(0) ClubName: ClubName1, ClubContactName: Bob, objectID: objectId1, ownerId: Bob-id
(1) ClubName: ClubName2, ClubContactName: Bob, objectId: objectId2, ownerId: Bob-Id

Now. I need to access that list and collect the ClubName and objectId to create the select. What I currently have in codeless doesn’t work.

Success is: the Select contains two things to pick from:
ClubName1
ClubName2

Here’s the logic:

Here’s the result of running the page:

You can see it here:
https://www.backendless.us/api/files/ui-builder/containers/support/index.html?page=select

LOL. I’m starting to think this can’t be done.
The list (myList, in your example) already exists and is kept in App Data so I have the information available for multiple pages.

Is it not possible to carry records from the database that are often referred to around in App Data so that API calls are minimized? I thought I read this was a best practice for minimizing API calls.

If it is possible to carry records in App Data - how do I manage moving them out of App Data so that I can do things with them, like creating Selects? I haven’t been able to find any tutorials or documentation on this topic. I figured I needed to use a list to do this, but maybe not. Given the struggles we are having on this thread.

Once data is in AppData you can retrieve it anywhere in the app.

For example, I expanded the demo above and now I place the array to AppData:

I also added a button to the page. When you click the button, the logic gets the array from AppData and uses data binding to display it:

You can experience it on the page itself:
https://www.backendless.us/api/files/ui-builder/containers/support/index.html?page=select

OK. So, in order to use the information I have loaded in App Data I need to put it in Page Data using some custom code? What is that code?

Here let me state my problem more completely. Clearly I’m doing something wrong some place and it might not be obvious.

When the user first enters the system. I check to see if they are a club official. If so, the layout displays additional menus they need for event management. At that time I generate a list of the clubs they are authorized to manage events for and place that list in App Data for use on the event management pages.

In the On Layout Enter event I have the following code:

All good to this point. The list of clubs the user is authorized for now exists in in App Data where it can be referred to.

Now, they enter an Event Management page and need to select the Club they want to work with so that the events associated with that club are then presented for selection.

This is where I get stuck. I need to pull that list out of App Data and create a Select using it.

What I currently have doesn’t work. Since there are only two actions, I am either (1) getting the data from App Data incorrectly (or in a way where it can’t be referred to) OR (2) setting up the data in the Select incorrectly (referring to the data wrong).

This is the error I get in the console.
image

From your previous reply it appears I am getting the data from App Data incorrectly (1). And I need to instead use some Custom Code to place the data into Page Data. What is that code?

And how did you get it into the puzzle piece format? The only codeless piece I can find for Custom Code looks like this:

image

THANK YOU. I truly appreciate the time you are spending on this.

No, you do not. The “custom code” you see there simply formats the JSON list to a string so I can display it for you in the Text component.

No, it is not, here’s why:

Do you hear that? That’s choirs of angels singing your praises. Thank You.

Can you spare the time to explain why this didn’t work? Was I deconstructing the list into it’s component parts? Which would explain why I was getting a length of 12 (a count of all the individual data elements) rather than 2 (a count of the number of records from the database) when I originally coded it. I just tacked the unexpected result up to - “Well, I didn’t understand how that works.” Rather than “There’s a problem here.”

What I have now works great. AND is much simpler.

On Layout Enter:

On Mounting an Event Management Form:

The lesson here is to always go back to the very first step when asking for help because the problem may be deeper than what I think.

Many Thanks.

The “Load Table objects” block always returns a list. Even if you put pageSize 1, it still will return a list of one.

What you had in your logic was wrapping the entire list of the Club records into another list. The final list was a list of one element, which in turn was a list of objects. And that sent the rest of the logic downhill to crash…

OK. I’m having another problem. Sorry. I thought I had this figured out. But lists are confounding me.

I have my list of clubs the user is authorized to manage in App Data. Now, I need to build a list of the events all those clubs are having to create, yes, another Select. :rofl:

I’m trying different things to get the ClubNumber data element out of the list in App Data to build the WHERE clause to get the Event records. I’m running out of ideas. This is what I’ve tried, all are giving me an empty list.

The complete set of logic: (because, yes, I can learn.)

Failed.

Failed.

Never expected this one to work, but you never know… Failed.

I’m running out of ideas.

Perhaps this will help:

Well. I’ve found lots of ways this doesn’t work and am once, again out of ideas - even with your wonderful hint. At this point, I’m simply trying to print out the WHERE clause. Once I nail that I’m pretty confident the rest will work.

My first thought was Ah-Ha! this is what is meant! Nope. Undefined.


Maybe I need to map it first - that seemed to work before…

Interestingly, this does give a result. Not the result I want, but I get something that’s not undefined. Which made me think I was on the right path.

image

Nope. Failed. Gives undefined.

What if I create a new object? Like how the Select was formed… Though why I’d need to create a new Object when presumably one already exists is a puzzle. But stranger things… Nope. Failed.

In the interest of being thorough…

I’m out of things to try. There is something fundamental here I don’t understand. I really wish your tutorials discussed lists that have data elements (properties).