Consequent get()'s on data Types isn't working

Hello everyone,

I’ve just encountered an odd issue with executing dataItem.get().get() command
Thing is that we need to get data from inside a data type contained another data type
E.g. User has Profile and we need to get data from Profile

For some reason, using User.get(Profile).get(someTextData) isn’t working and doesn’t throw any error. Plugin just stops working at the User.get(Profile).get(someTextData) execution.
After some reloads I was able to execute the command for a few times but not completely.
Logging in “User.get(Profile)” and .get(someTextData) inside browser console works fine.

Appreciate any advice!

Thanks, Alex.

Did the .get().get() used to work?

To get this straight: User is a data type, Profile is another data type? User has one Profile? Could it be that those are async calls?

1 Like

is this inside an element? Is the field name used as parameter for the .get the display id of the field or the actual bubble id (the one you see inspecting app.user_types)?

1 Like

I had that issue before and nailed it down to a sync issue. Try store the first get() in a variable then get() that.

let var = datatype.get();
var.get();

See if that works.

Ye, it worked but odd way
Script was able to retrieve like 4 out of 5 calls and just terminated
But I was able to reach this only 1-2 times by reloading and tweaking the calls
Making a call, e.g. const profile = user.get(Profile), print in console, save as console variable and call .get(someTextData) again works as well

User is a data type, Profile is another data type inside User, that’s correct
User can have only 1 Profile is correct statement either

Regarding to async calls, I’ve tried to handle the call like async but no result as well

Wasn’t able to find anything on forum and inside docs either but it looks to me like a common issue so wanted to ask for help on forum, so to avoid walking blindly

Ye, this is inside the element, field name used as parameter
I ensured that data used was properly received and making such call in the browser console works
Call randomly executes but I wasn’t able to find a stable solution

Thanks for your response.

Tried it the way you described and also was thinking about syncing but no result, unfortunately
I’ve also tried to handle first .get() as promise (dunno if Bubble changed the structure without announcement) but no effect as well
But agreed that it still sounds and looks like sync issue

Yeah, everything is async. Just add a async function(instance, context…)

as far as I know client side plugins are not async, they still use the previous architecture: when the code runs any data access blocks the execution on the first run, then once the data is available the code runs again from the beginning. If you access different data multiple times the code will actually run multiple times, and only the last one will have all the data available and will run completely.
If your field name is correct what you are probably seeing is multiple partial runs and the the complete run with all the data.
Your code need to account for this behaviour and execute side effects only after you access all the data you need.
It goes without saying that any data access in an async function inside client side plugins will not behave as you expect, maybe this is the problem.

1 Like

Thank you for your response
I’ve tried this but unfortunately, it is for server-side actions only
Using async function(instance, context) will trow an error for element actions

That sounds useful to note, thanks!
Will give it a shot.
I guess, that we should collect the data at first and check if everything’s fine before proceeding

That makes some things a whole lot clearer for some weird behaviours I’ve experienced in the past.