Unable to create a new row in a local table or airtable DB

Hi Thunkers,

Me again…
Can I borrow a pair of better educated eyes than mine???
I’ve worked on the following for a couple of days and I’m struggling to understand what the issue is.
For ease of sharing I’ve simplified the task but the result is still the same.
In short I’m unable to create a new row in the table, in either local, such as this example or Airtable.
I’ve put in some traces to a label so I can narrow down the issue, which doesn’t help as it does not update the label.

The issue I think is due to the “for loop” in buildCarasol2, Running a trace without the loop on the vidObj variable generates a JSON object with the expected content. But I seem unable to extract any data using the complete function.


Pls excuse the rambling… But any guidance would be welcome.

Thanks

1 Like

What does the full JSON (app variable vidObj) look like as text?

I’m grabbing at straws a bit but just wondering if the “results” property is a list… I’m assuming it is. Would be good to see the full JSON.

For testing purposes, what happens if you just have a “set Label’s Text” block (and nothing else) inside the “for each item j” loop? Does the label value change?

1 Like

In your for loop “buildCarasol2”, where did you get “vObj” from? It should be "j’ otherwise, the loop has no value.

1 Like

@tatiang So this is an example of the JSON like…

{
“id”: 581389,
“results”: [
{
“id”: “60064a8b4ca676003f0bad08”,
“key”: “H1WYnJF1Pwo”,
“name”: “Space Sweepers”,
},
{
“id”: “6018a0e63ff2df004036c2a9”,
“key”: “jXGxuUHmVQc”,
“name”: “[Behind the Scenes] Space Sweepers”,
}
]
}

For testing purposes, what happens if you just have a “set Label’s Text” block (and nothing else) inside the “for each item j” loop? Does the label value change?

This breaks things completely and throws the “Something had gone wrong. Check your blocks and reset this page” message block

@muneer
maybe I’m misunderstood but I thought the value vidObj was passed into buildCarasol2 via vidObjs.
Hence in the for loop j should actually be vidObjs as in the screenshot below and the “get property (results) of object get object from JSON “app variable vidObj”” should work as its a (global app object) or calling vidObjs should work also as it is the passed version of the same global object…

That said I have tried changing j in the for loop to either version… No change
Changed the current app variable vidObj to j as you suggested… No change

The only time the label changes is if I set the label to vidObj before the for loop then output is a JSON or app variable vidObj as object object…

FYI test with both generate & get JSON… No difference outcome…

You have some variable name conflicts that are not only confusing to me but that are going to cause unpredictable behavior in your app.

Your app variables, function input variables and loop variables should have unique names. And probably best – for those looking at your blocks – if they aren’t really really similar like vidObj and vidObjs… but I digress.

So there’s a problem with having the “buildCarasol2” function’s input variable named vidObjs and the “for each item” loop variable also named vidObjs. Differentiate those two names and then re-select the “vidObj” and “vidObjs” variables inside of the “buildCarasol2” function to make sure you’re using the right one.

2 Likes

I was referring to this from your first post

This variable was never mentioned somewhere else.

From your JSON, results is a list containing a single element so you may refer to it using the list block without using the for loop. This is if your JSON will always return a single element.

The latest screenshot of your function “buildCarasol2” should not work because you are trying to get the value of vidObj while creating the row whereas your looping variable is vidObjs so this results in null value.

1 Like

Thanks both! your probably right looking at my screenshots in the cold light of day, I’m confusing myself!
The various objects are mostly my multiple attempts to get something to work, I’ll take your suggestion and clean things up (simplify) and see if that makes a difference.
Cheers

@muneer ah yes I’m with you, yep makes sense. I can probably just run with a list… But I am still stumped as to why even with just one element I’m unable to get the desired results…
(Obviously ignoring the incorrect row creation reference) Label2 should still trace out the text right?

2 Likes

When an exception error occurs, the code does not continue executing and therefore it stops when the first assignment of null is encountered which means it never reaches to “Label2”.

1 Like

Thanks!

I worked out eventually what the actual problem was!
It was in the vidSearch function I mistakenly used “generate JSON from object” instead of “get property of object” this obviously was creating a JSON which meant the for loop was failing in the buildCarasol2 function as it was looking for an object.

Thanks both @muneer @tatiang for casting your eye, I need to pay more attention to the details :slight_smile:

1 Like

Hmmm I suggest you do this in firebase it’s way easier

1 Like

hmm ok thank I look into it.
Forgive my ignorance as I’m pretty much a newbie…
Under which uses case would you use firebase over airtable or other cloud db’s?

1 Like