How to manage the properties in 'update' function when they return null?

Hi everyone,

In the “update” function of an element I work on as a plugin, I use in the beginning lines like:
const list1 = properties.list1 ;

In this plugin I face a problem that this “sometimes” not return the value when it come from “do a search for …” data source.

what can I do to solve this?

I am assuming you are trying to access the list with data type “anything”.

To access the list in the Bubble plugin editor -

var length_data = properties.anything_data.length(); //lenght of input list
var list_data = properties.anything_data.get(0, length_data); //input data list

You need to run this code.

Checkout Bubble Plugin Development Course?

Thank you @ankur1
I am trying to access lists with data type “text” and “number”.

@salemmo409 I think you can use the code for "text/number " list.

It’s the same dude.

There’s a chance you are accessing the value of that input before it’s populated with a value

I would do something like the following at the top of your update. This way the function doesn’t execute without the needed data.

if (properties.list == null || properties.list == undefined ) {
1 Like

@ankur1 I am sorry I forgot to mention that I did this indeed. However, the problem persists.

Hi @jared.gibb,
So when the data is not populated yet the function will exit and the rest of the code will not be executed?
If this is the case then this is the problem I am trying to solve, the problem is that the data exist in the database but “sometimes” the plugin not get it and the code not executed or executed with null values.

That’s exactly right. What will happen is that one of the data is populated the code block will try to run again and it will be able to because the data has finally arrived from the db and been touted to the plugin inputs. Every time any of your plugin dynamic inputs are modified in any way, the entire update function runs again. .

I wish someone had showed me this meme a few years ago when I started learning JavaScript.

It’s a mad world out there. Somehow JavaScript makes it crazier. Tips I would give myself if I were starting to learn today:

  • the event loop, aka: (dis)order of operations
  • dynamic types
  • what happens when you type console.log(1 + “1”)

As I understand it, making the code exit early or letting it execute completely does not change the fact that the function is executed again when the data is populated and the fact that the data will certainly be displayed at the end. If my understanding is correct, I got the answer I needed here.